Home  >  Article  >  Database  >  How does mysql perform year, month, and day group statistical query based on date?

How does mysql perform year, month, and day group statistical query based on date?

藏色散人
藏色散人forward
2020-05-16 13:22:442491browse

How does mysql perform year, month, and day group statistical query based on date?

Use YEAR(), MONTH(), DAY() to get the year, month and 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)    获取日

Use date_format(application_date, '%Y'), which can be customized Date format

SELECT date_format(application_date, "%Y") as year, count(1) FROM patent GROUP BY date_format(application_date, "%Y")

How does mysql perform year, month, and day group statistical query based on date?

Recommended: "mysql tutorial"

The above is the detailed content of How does mysql perform year, month, and day group statistical query based on date?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete