sql >> Databáze >  >> RDS >> Mysql

MySQL dotaz Select, SUM, LEFT JOIN

Zkuste toto:

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. Jak spustím automatické zvyšování od určitého bodu?

  2. Odlišný přístup k použití klauzule IN v MySql

  3. Chyba s dotazem CREATE TABLE MySQL

  4. Obnovení hlavní databáze SQL Server