How to fetch the no: of weekly inserted records in MySQL


SELECT
  COUNT(*) AS reports_in_week,
  DATE_ADD(created_at, INTERVAL(1-DAYOFWEEK(created_at)) DAY) as start_day,
  DATE_ADD(created_at, INTERVAL(7-DAYOFWEEK(created_at)) DAY) as end_day
FROM
  your_table_name
GROUP BY
  YEAR(created_at) + .01 * WEEK(created_at)

The desired output will be.



Comments

Post a Comment

Popular posts from this blog

How to SSH to remote server without entering password each time.

How to redirect a URL in NGINX

Ruby on Rails Installation on Windows 7