Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8749555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:42:49+00:00 2026-06-13T12:42:49+00:00

How to get count (last 4 weeks records and week range) group by week

  • 0

How to get count (last 4 weeks records and week range) group by week range?

Week range means 22-28, 15-21,8-14, 1-7

I tried this

SELECT WEEK(PERIOD), SUM(CLICKS)
  FROM TABLE
 WHERE PERIOD >= NOW() - INTERVAL 4 WEEK
 GROUP BY WEEK(PERIOD)

and

SELECT WEEKOFYEAR(`date`) AS period,
       SUM(clicks) AS clicks
  FROM `tablename`
 WHERE `date` >= CURDATE() - INTERVAL 4 WEEK
 GROUP BY period
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:42:50+00:00Added an answer on June 13, 2026 at 12:42 pm

    If you mean last 4 weeks by exactly each 7 x 24 days prior to today, up to the second, then

    SELECT CASE WHEN PERIOD >= NOW() - INTERVAL 4 WEEK
                        AND PERIOD < NOW() - INTERVAL 3 WEEK THEN '22-28 days ago'
                   WHEN PERIOD >= NOW() - INTERVAL 3 WEEK
                        AND PERIOD < NOW() - INTERVAL 2 WEEK THEN '15-21 days ago'
                   WHEN PERIOD >= NOW() - INTERVAL 2 WEEK
                        AND PERIOD < NOW() - INTERVAL 1 WEEK THEN '8-14 days ago'
                   WHEN PERIOD >= NOW() - INTERVAL 1 WEEK
                        THEN 'up to 7 days ago'
                   END WeekPeriod, IFNULL(SUM(CLICKS),0) TotalClicks
      FROM TABLE
     WHERE PERIOD >= NOW() - INTERVAL 4 WEEK
     GROUP BY CASE WHEN PERIOD >= NOW() - INTERVAL 4 WEEK
                        AND PERIOD < NOW() - INTERVAL 3 WEEK THEN '22-28 days ago'
                   WHEN PERIOD >= NOW() - INTERVAL 3 WEEK
                        AND PERIOD < NOW() - INTERVAL 2 WEEK THEN '15-21 days ago'
                   WHEN PERIOD >= NOW() - INTERVAL 2 WEEK
                        AND PERIOD < NOW() - INTERVAL 1 WEEK THEN '08-14 days ago'
                   WHEN PERIOD >= NOW() - INTERVAL 1 WEEK
                        THEN '01 to 7 days ago'
                   END
     ORDER BY WeekPeriod
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to get the total amount of visitors for this week and last
I tried numerous times over the last few weeks to get a server side
I'm trying to get a count of emails received during a date range using
I need to get the following ratio (daily sign up count)/(last 30 days rolling
When I use this query: SELECT COUNT(*) FROM `my_table` WHERE DATEDIFF(NOW(), updated) > 2
I'm trying to get a count of how many PDFs were created last month.
I don't know if this is the right section... but here goes: Last weeks
i have a table which has many fields but i want to get count
I made server/ client application in WCF. How get count of connected clients? And
i want to get the count of photos in photoLibrary. Currently, i'am able to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.