- Instant help with your Sql coding problems

Count total rows by year in MySQL

Question:
How to count total rows by year in MySQL?
Answer:
SELECT YEAR(publish_date) as publishYear, COUNT(*) AS totalRows 
FROM article 
GROUP BY YEAR(publish_date);
Description:

If you need to create a report where data is to be represented by year, you can use the built-in YEAR() function in the GROUP BY clause.

The YEAR function returns the year for date, in the range 1000 to 9999, or 0 for the “zero” date.

Reference:
YEAR reference
Share "How to count total rows by year in MySQL?"