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

Come faccio a raggruppare un campo data per ottenere risultati trimestrali in MySQL?

Penso che questo dovrebbe fare il lavoro:

SELECT YEAR(leaddate) AS year, QUARTER(leaddate) AS quarter, COUNT(jobid) AS jobcount
  FROM jobs
 WHERE contactid = '19249'
 GROUP BY YEAR(leaddate), QUARTER(leaddate)
 ORDER BY YEAR(leaddate), QUARTER(leaddate)