使用YEAR(), MONTH(), DAY() 來取得年月日
SELECT YEAR(application_date) as years, count(1) FROM patent GROUP BY YEAR(application_date) ORDER BY years -- YEAR(application_date) 获取年份 -- MONTH(application_date) 获取月份 -- DAY(application_date) 获取日
使用date_format(application_date, '%Y'),可自訂日期格式
SELECT date_format(application_date, "%Y") as year, count(1) FROM patent GROUP BY date_format(application_date, "%Y")
推薦:《mysql教學》
以上是mysql怎麼根據date做年,月,日分組統計查詢的詳細內容。更多資訊請關注PHP中文網其他相關文章!