Home > Database > Mysql Tutorial > 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?

藏色散人
Release: 2020-05-16 13:22:44
forward
2542 people have browsed it

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)    获取日
Copy after login

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")
Copy after login

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!

Related labels:
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template