Mysql
 sql >> Base de données >  >> RDS >> Mysql

Comment additionner avec des conditions sur d'autres colonnes

Utilisez cette requête ci-dessous :-

 CREATE TEMPORARY TABLE t1 (PONumber decimal(18, 2) NOT NULL,POdate date NOT NULL,customername varchar(200) NOT NULL,description varchar(200) NOT NULL);
 INSERT INTO t1(PONumber,POdate,customername,description) 
 select distinct PONumber,POdate,customername,description from tb_po;

 select  p.PONumber,p.podate,p.customername,p.description,
(select sum(q.deliveryqty) from tb_spb q where p.PONumber=q.PONumber AND p.description = q.description) as Total
 from t1 p;

drop table t1;

Il vous donnera la sortie requise.