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

Grupper sum fra to tabeller efter dato i MySQL

Dette får ikke datoer med nuller, for det skal du enten bruge en datotabel eller en lagret procedure til at gå gennem datoer. En måde at gøre det på er et undervalg fra en fagforeningsforespørgsel (utestet):

SELECT commission_date, SUM(click_commission), SUM(lead_commission), SUM(total_commission)
FROM (SELECT DATE(click.time) AS commission_date, click.commission AS click_commission,
             0 AS lead_commission, click.commission AS total_commission
      FROM click
      UNION ALL
      SELECT DATE(lead.time) AS commission_date, 0 AS click_commission,
             lead.commission AS lead_commission, lead.commission AS total_commission
      FROM lead) AS foo
GROUP BY commission_date
ORDER BY commission_date



  1. Oprettelse af en database i Cloud Sites

  2. Forbind online mysql-database med den lokale xampp-server ved hjælp af php

  3. Præstationsoverraskelser og antagelser:GRUPPE EFTER vs. DISTINCT

  4. Match/Imod og transaktioner