sql >> Database teknologi >  >> RDS >> Mysql

Flet to tabeller i én SQL-forespørgsel og gør datoværdierne unikke

Brug union all og group by :

SELECT Date, Product, SUM(Inbound) as Inbound, SUM(Outbound) as Outbound
FROM ((SELECT Inbound_Date As Date, Product, SUM(Quantity) as Inbound, 0 as Outbound
      FROM Inbound
      GROUP BY 1,2
     ) UNION ALL
     (SELECT Outbound_Date, Product, 0 as Inbound, COUNT(*)  as Outbound 
      FROM Outbound
      GROUP BY 1,2
     )
    ) io
GROUP BY Date, Product;


  1. 2ndQuadrant Deutschland – Special Training Opening Bargain

  2. Spotlight Cloud-sikkerhedsfunktion - Fjern bogstaver

  3. Fejlfinding af SQL Server-transaktionelle replikeringsproblemer

  4. hvordan man præfikser en streng før sekvens genereret af postgresql?