----按月 (本年)

SELECT
   CONCAT(MONTH(createtime),"月") createtime,
   CONCAT (count(id),'次') countNum 
FROM
  表
    where 
    DATE_FORMAT(createtime, '%Y') = date_format( now( ), '%Y' )
GROUP BY
    MONTH(createtime)
ORDER BY
    MONTH(createtime) asc

---按季度
SELECT
    count(id) countNum,
    QUARTER(createtime) starttime
FROM
    表
GROUP BY
    QUARTER(createtime)
ORDER BY
    QUARTER(createtime);

Logo

更多推荐