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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:35:12+00:00 2026-06-10T10:35:12+00:00

I am trying to find the sum of values between two dates in this

  • 0

I am trying to find the sum of values between two dates in this case I would always want to keep one date static. Example finding the value between dates April to July, keeping April static, so therefore another case could be sum of values between dates April to May, again keeping april static. I have been working on several queries for quite sometime but havn’t been sucessful in doing so could you have a look at the following SQLFiddle here and aid me please I would really appreciate the help

  • 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-10T10:35:13+00:00Added an answer on June 10, 2026 at 10:35 am

    Why not just add another CASE statement:

    sum(case when pay_date between '2012-04-01' and '2012-06-01'
            then amount end) range_amount
    

    so your query would be:

    SELECT p.name,
           v.v_name,
           SUM(CASE
                 WHEN MONTH(py.pay_date) = 4 THEN amount
               end) april_amount,
           SUM(CASE
                 WHEN MONTH(py.pay_date) = MONTH(CURDATE()) THEN amount
               end) current_month_amount,
           SUM(CASE
                 WHEN MONTH(py.pay_date) = MONTH(CURDATE()) - 1 THEN amount
               end) previous_month_amount,
           SUM(CASE
                 WHEN pay_date BETWEEN '2012-04-01' AND '2012-06-01' THEN amount
               end) range_amount
    FROM   persons p
           LEFT JOIN vehicle v
                  ON p.id = v.person_veh
           LEFT JOIN payment py
                  ON p.id = py.person_id
    GROUP  BY p.name,
              v.v_name
    

    see SQL Fiddle with Demo

    Then if you want to change the date range, you can pass in a value for the end date and make that a variable.

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

Sidebar

Related Questions

Trying to calculate sum of checked tr's. var totalqt=0; totalqt=totalqt + $(this).closest(tr).find(#qt).text(); It gets
i am trying to find the max values of a sum result but i
I'm trying to find the sum of specific values within a table, using SQL.
Im trying to find a set of results in a database based on dates.
I'm trying to retrieve two columns from the DB with iBatis. I want to
I am trying to sum the values of a nD array along a particular
I am trying to write T-sql script which will find open records for one
i'm trying to figure out how to sum certain values of a multi-dimensional array
This is the expression I'm trying to evaluate: Sum(IIF(QUALITY<=9.0,1.0,0.0)) The problem is that string
Trying to find a standard. The CmdLet will process data - multiple input, defined

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.