1. 程式人生 > >mybatis中關於年,季,月,周,日的統計問題

mybatis中關於年,季,月,周,日的統計問題

 

關於統計年,季,月,周,日資料問題如:銷售額,訪問量等,從網上百度了一些,但是我執行時不管用,在此基礎上我改了一些程式碼如下方法:


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")