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

MySQL WEEK() :Få alle uger inden for datointerval (med/uden registreringer)

Forudsat at du har en tabel med heltal (kaldet `numbers`). nedenfor):

SELECT COALESCE(n, 0) AS num_complaints, CONCAT('Week ', i) AS `week` FROM (SELECT i FROM numbers WHERE i BETWEEN (SELECT WEEK(MIN(complaintRaisedDate)) FROM events LIMIT 1) AND (SELECT WEEK(MAX(complaintRaisedDate)) FROM events LIMIT 1)) week_ranges LEFT JOIN ( SELECT count(id) AS n, WEEK(complaintRaisedDate) AS weeknum FROM events WHERE categoryId=1 GROUP BY weeknum) weekly_tallies ON week_ranges.i = weekly_tallies.weeknum ORDER BY `week` ASC;

SQL violin



  1. Hvordan gemmer man en rækkes multiple kolonnes sum på den samme tabels samme rækkes en anden kolonne?

  2. HVIS IKKE FINNES VIRKER IKKE

  3. Sammenligning af Windows Azure VM-ydeevne, del 2

  4. cURL og PHP viser 1