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 9273433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:06:55+00:00 2026-06-18T16:06:55+00:00

I have a mysql table with following columns order_id customer_id total_amount date_added Now, i

  • 0

I have a mysql table with following columns

order_id
customer_id
total_amount
date_added

Now, i would like to make a query for a particular customer to know if the customer has made more than or equal to 12000$ amount of order over six months period of his/her order history. The period is not recent.

Is there any solution for this?

Regards,
Dipen

  • 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-18T16:06:57+00:00Added an answer on June 18, 2026 at 4:06 pm
    select sum(total_amount) >= 12000 over_12000
    from mytable
    where customer_id = nnn
    and date_added between 'YYYY-MM-DD' and date_add('YYYY-MM-DD', interval 6 month)
    

    Replace nnn with the particular customer ID, and YYYY-MM-DD with the start of the 6 month period that you’re interested in.

    UPDATE:

    This will use the 6 month period leading up to the customer’s last order:

    select sum(total_amount) >= 12000 over_1200
    from mytable join (select max(date_added) last_date
                       from mytable
                       where customer_id = nnn) last
    where customer_id = nnn
    and date_added between last_date and date_sub(last_date, interval 6 month)
    

    UPDATE 2:

    select m1.date_added end_date, sum(m2.total_amount) >= 12000 
    from mytable m1 join mytable m2 on m2.date_added between date_sub(m1.date_added, interval 6 month) and m1.date_added and m1.customer_id = m2.customer_id
    where m1.customer_id = nnn
    group by end_date
    order by end_date
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three mysql table from same database Db1. Three tables have following columns.
I have a MySQL table with a structure like the following: I'm looking for
I would like to ask a quick question regarding a mysql query. I have
I have 2 mysql tables : Question with the following columns : id, question,
I have a MSSQL table stores that has the following columns in a table:
I have 2 mysql tables 1. questions: with the following columns: id, title, answer1,
I have a MySQL table with the following data (simplified): INSERT INTO `stores` (`storeId`,
I have the following Mysql Table Order table status 0 - incomplete status 1
I have the following MySQL table structure: num field company phone website 1 Gas
I have a following mysql table with a lot (3000+) of values: [id] [parent_id]

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.