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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:07:05+00:00 2026-06-14T23:07:05+00:00

I have SQL tables: id_details year-month type (only have 2 values , income and

  • 0

I have SQL tables:

id_details
year-month
type (only have 2 values , income and outcome)
amount

and table have row like this:

(year-month)      (type)     (amount)
 November-2012    income      50000
 November-2012    income      30000
 December-2012    income      20000
 November-2012    outcome     10000
 December-2012    outcome     50000
 December-2012    income      10000

What I want is, showing a query with result like this:

 (year-month)    (sum income)     (sum-outcome)   (sub-total balance)
 November-2012    80000             10000          70000
 December-2012    30000             50000          -20000 

finally

  total-balance = 50000

How can I do this?
or can you recommend me better tables design?

  • 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-14T23:07:07+00:00Added an answer on June 14, 2026 at 11:07 pm
    SELECT `year-month`,
           SUM(CASE WHEN type = 'income' THEN amount ELSE 0 END) `sum-income`,
           SUM(CASE WHEN type = 'outcome' THEN amount  ELSE 0 END) `sum-outcome`,
           SUM(amount) `sum-total balance`
    FROM <JOINS>
    GROUP BY `year-month`
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have 3 Tables is my SQL Database: First Table: Room: ID <pk>, Roomname
In SQL Server 2008 I have two tables. One table for users: id_user -
If i have a sql table with column like this id version subversion 1
I have an SQL database with a set of tables that have Unique Id's.
I have the following tables in SQL Server 2005 ReceiptPoint: ID (PK), Name GasIndexLocation:
i have the following tables in sql server: photoalbumsTable: album_ID album_caption albumtagmap id album_id
I have an SQL table defined as below: CREATE TABLE [TestComposite] ( ID int,
I have an SQL table written in MSSQL: create table [action] ( action_id bigint
I have a SQL table with following fields ID, Rly, Shed, Loco_no, shed, Date_failure,
I have a SQL table that has a primary key ( Row_id ) that

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.