sql >> Database >  >> RDS >> Mysql

MySQL-query Select, SUM, LEFT JOIN

Probeer dit:

SELECT S.Items as Products, 
       COALESCE(PS.Quantity, 0) as [Products Sold], 
       COALESCE(PP.Quantity, 0) as [Products purchased]
From Stock S 
LEFT JOIN (SELECT Items, SUM(Quantity) AS Quantity 
           FROM products_purchased 
           GROUP BY Items
         ) AS PP ON S.Items = PP.Items 
LEFT JOIN (SELECT Items, SUM(Quantity) AS Quantity 
           FROM products_sold 
           GROUP BY Items
         ) AS PS ON S.Items = PS.Items; 



  1. PHP, MySQL:e-mail ontvangen, automatisch zoeken in DB en e-mail verzenden op basis van de resultaten

  2. Hoe groeipercentage week na week te berekenen in MySQL

  3. Lon/Lat-volgorde bij gebruik van het ruimtelijke POINT-type met MySQL

  4. Hoe u een gebruiker kunt maken met superuser-rechten in PostgreSQL