sql >> Base de Datos >  >> RDS >> Mysql

Dos donde condición para la misma columna usando group by

Creo que esta es la consulta que está buscando:

SELECT t1.branch_name, 
       COALESCE(SUM(send.vqty), 0) AS send, 
       COALESCE(SUM(receive.vqty), 0) AS received 
FROM t1  
LEFT JOIN t2 AS send on t1.id = send.VBRNCH  
LEFT JOIN t2 AS receive on t1.id = receive.VTOBRN 
GROUP BY t1.branch_name

Demostración aquí