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

  • SEARCH
  • Home
  • 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 8890687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:33:33+00:00 2026-06-14T22:33:33+00:00

The problem I’m running into is when running this query it starts the week

  • 0

The problem I’m running into is when running this query it starts the week interval from the current date (minus 7 days from current date). I want to do all previous 10 weeks (Sun-Mon). So if my current date is on a Monday, Tuesday, or Wednesday, I want it to start on the most recent Sunday then look back at the previous 10 weeks. I believe I have to use WEEKDAY or DAYOFWEEK in the DATE_SUB but have tried with no avail:

SELECT
    SUM(MT.QUANTITY) as qty,
    WEEKDAY(MT.TRANS_DATE) AS WEEKDAY,
    WEEK(MT.TRANS_DATE) AS WEEK,
    YEAR(MT.TRANS_DATE) AS YEAR
FROM
    mytable MT
WHERE
        MT.TRANS_DATE > DATE_SUB(CURDATE(), INTERVAL 10 WEEK)
GROUP BY WEEK
  • 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-14T22:33:34+00:00Added an answer on June 14, 2026 at 10:33 pm

    Try with DATE_SUB(STR_TO_DATE(CONCAT(YEAR(CURDATE()),WEEK(CURDATE()),' Sunday'), '%X%V %W'),INTERVAL 10 WEEK), like this:

    SELECT
        SUM(MT.QUANTITY) as qty,
        WEEKDAY(MT.TRANS_DATE) AS WEEKDAY,
        WEEK(MT.TRANS_DATE) AS WEEK,
        YEAR(MT.TRANS_DATE) AS YEAR
    FROM
        mytable MT
    WHERE
            MT.TRANS_DATE > DATE_SUB(STR_TO_DATE(CONCAT(YEAR(CURDATE()),WEEK(CURDATE()),' Sunday'), '%X%V %W'),INTERVAL 10 WEEK)
    GROUP BY WEEK
    

    Also you can use the other way pilcrow suggested:

    SUBDATE(CURDATE(), DAYOFWEEK(CURDATE()) - 1)
    

    Which is a little more readable…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently running into a problem where an element is coming back from
I have a French site that I want to parse, but am running into
Problem description: I want to print only the source and destination address from a
Problem: I'm streaming my video from a php file with stream_get_contents(); using Flowplayer as
Problem is like this: Suppose there are records in dataTable with FruitType as A
Problem is like this: I have two winapi application's. There is only one way
Problem: I have an address field from an Access database which has been converted
Problem: Given a list of strings, find the substring which, if subtracted from the
Problem solved: Thanks guys, see my answer below. I have a website running in
Problem: To obtain the id from a radio button using jQuery on click or

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.