关于统计年,季,月,周,日数据问题如:销售额,访问量等,从网上百度了一些,但是我执行时不管用,在此基础上我改了一些代码如下方法:
年
SELECT COUNT(1) productCount,YEAR(createTime) years
FROM `gm_buyerproduct`
WHERE YEAR(createTime) = YEAR("2018-12-07 16:38:46")
季(控制在具体某年的哪个季度)
SELECT COUNT(1) productCount,QUARTER(createTime) createTime
FROM `gm_buyerproduct`
WHERE QUARTER(createTime)=QUARTER("2018-08-09 18:56:41") AND YEAR(createTime)=YEAR("2018-08-09 18:56:41")
月(控制在具体某年的哪个月)
SELECT COUNT(1) productCount,MONTH(createTime)`monthname`,YEAR(createTime) years
FROM `gm_buyerproduct`
WHERE MONTH(createTime)=MONTH("2018-12-01 17:02:12") AND YEAR(createTime)=YEAR("2018-12-01 17:02:12")
周(控制在具体某年的哪个周)
SELECT COUNT(1) productCount,WEEK(createTime) weeks
FROM `gm_buyerproduct`
WHERE WEEK(createTime)=WEEK("2018-07-01 18:56:41") AND YEAR(createTime)=YEAR("2018-07-01 18:56:41")
日
SELECT COUNT(1) productCount,createTime
FROM `gm_buyerproduct`
WHERE DATE_FORMAT (createTime,"%Y-%m-%d")=DATE_FORMAT("2018-07-01 18:56:41","%Y-%m-%d")
原文地址:https://www.cnblogs.com/lc-index/p/10093123.html