1. 程式人生 > >MySQL中按年+月統計期間資料

MySQL中按年+月統計期間資料

sql程式碼:

SELECT
	DATE_FORMAT(d.create_date, '%Y-%m') AS MONTH,
	sum(d.apply_amount) AS money
FROM
	test d
WHERE
	DATE_FORMAT(d.create_date, '%Y-%m') BETWEEN '2017-02%' AND '2018-02%'
GROUP BY
	MONTH
ORDER BY
	MONTH

結果圖: