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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:39:38+00:00 2026-06-14T09:39:38+00:00

I have the below query which displays data like so: Income Type This Month

  • 0

I have the below query which displays data like so:

Income Type This Month  Last Month  This Year   Last Year
1           179640.00   179640.00   179640.00   179640.00
2           12424440.00 12424440.00 12424440.00 12424440.00


Select
  Income_Type As [Income Type],
  Sum(Income_Amount) As [This Month],
  Sum(Income_Amount) As [Last Month],
  Sum(Income_Amount) As [This Year],
  Sum(Income_Amount) As [Last Year]
From Income I
Left Join Finance_Types FT On I.Income_Type = FT.Type_ID
Group By
Income_Type

The Income table has a Income_Date which is a datetime column.

I’m struggling to get my head around how I would pull out the data for ‘This Month’, ‘Last Month’, ‘This Year’, ‘Last Year’ with the correct Sums in one query if possible?

  • 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-14T09:39:39+00:00Added an answer on June 14, 2026 at 9:39 am

    Use date functions:

    SUM(CASE WHEN YEAR(yourdatefield) = YEAR(GetDate()) - 1 THEN Income_Amount ELSE 0 END) AS 'Last Year'
    

    That case statement only returns the Income_Amount if it was the last year, so you would be summing up only those amounts.

    If you’re not using SQL Server, the syntax might be a bit different.

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

Sidebar

Related Questions

I have a result from a query like the below, which does not have
I have written SQL query which brings data from multiple tables and displays the
I'm using Sql-Server, and I have the below query which returns all columns that
I have a T-SQL query as below which queries a table holding the search
I have below query I am trying to show message 'No SubSource for this
I have a query which retrieves Some data. I want to display that data
I have this script that displays all the users images which i will display
Good morning, mysql query which displays cases that have a date field completed &
If I have the query below which selects a forum board, but the board
I have the below query in a postgresql database SELECT * FROM accounts where

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.