Rumah >pangkalan data >tutorial mysql >mysql怎么根据date做年,月,日分组统计查询

mysql怎么根据date做年,月,日分组统计查询

藏色散人
藏色散人ke hadapan
2020-05-16 13:22:442539semak imbas

mysql怎么根据date做年,月,日分组统计查询

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

5df6a5d7004a01b99ec5de0090a4b21.png

推荐:《mysql教程

Atas ialah kandungan terperinci mysql怎么根据date做年,月,日分组统计查询. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Kenyataan:
Artikel ini dikembalikan pada:cnblogs.com. Jika ada pelanggaran, sila hubungi admin@php.cn Padam