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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:59:49+00:00 2026-06-08T13:59:49+00:00

I have 2 statements in sqlite 1st Statement: Select SUM(GrossQty) As GQTY, SUM(NetQty) As

  • 0

I have 2 statements in sqlite

1st Statement:

Select SUM(GrossQty) As GQTY, SUM(NetQty) As NQTY
  From NSales 
  Where IMonth=5 And IYear=2012 And IDay>15

Result:

GQty  NQty
 30    25

2nd Statement

Select SUM(GrossQty) As GQTY, SUM(NetQty) As NQTY
  From NSales 
  Where IMonth=6 And IYear=2012 And IDay<10

2nd Result:

GQty  NQty
 20    15

How can I combine these statements so that I get both these results added together like this?

Desired Result:

GQty  NQty
 50    40
  • 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-08T13:59:52+00:00Added an answer on June 8, 2026 at 1:59 pm

    You can do:

    SELECT 
        SUM(a.GQTY) AS GrossQty, 
        SUM(a.NQTY) AS NQTY
    FROM
    (
        SELECT SUM(GrossQty) AS GQTY, SUM(NetQty) AS NQTY 
        FROM   NSales 
        WHERE  IMonth = 5 AND IYear = 2012 AND IDay > 15
    
        UNION ALL
    
        SELECT SUM(GrossQty), SUM(NetQty)
        FROM   NSales
        WHERE  IMonth = 6 AND IYear = 2012 AND IDay < 10
    ) a
    

    Alternatively:

    SELECT 
        a.GQTY + b.GQTY AS GQTY,
        a.NQTY + b.NQTY AS NQTY
    FROM
    (
        SELECT SUM(GrossQty) AS GQTY, SUM(NetQty) AS NQTY 
        FROM   NSales 
        WHERE  IMonth = 5 AND IYear = 2012 AND IDay > 15
    ) a
    CROSS JOIN
    (
        SELECT SUM(GrossQty) AS GQTY, SUM(NetQty) NQTY
        FROM   NSales
        WHERE  IMonth = 6 AND IYear = 2012 AND IDay < 10
    ) b
    

    Or you can use CASE expressions and avoid having to issue two separate subselects (harder to read):

    SELECT 
        SUM(
            CASE WHEN (IMonth = 5 AND IYear = 2012 AND IDay > 15) OR
                      (IMonth = 6 AND IYear = 2012 AND IDay < 10) THEN
                      GrossQty
                 ELSE 0
            END) AS GQTY, 
        SUM(
            CASE WHEN (IMonth = 5 AND IYear = 2012 AND IDay > 15) OR
                      (IMonth = 6 AND IYear = 2012 AND IDay < 10) THEN
                      NetQty
                 ELSE 0
            END) AS NQTY
    FROM NSales
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some codes read the query results from sqlite: while (sqlite3_step(statement) == SQLITE_ROW)
I have the following function for SQLite select statement public Boolean itemFound(String cartId,Long ItemId){
I have heard that prepared statements with SQLite should improve performance. I wrote some
I'm experiencing some weird behavior with SELECT statements in sqlite. There is one table
Are conditional if/case/when statements supported in sqlite triggers? Let`s say I have the following
I have written dynamic insert part.When I excute he Insert statement into sqlite browser
I want to use strings so I don't have to have if statements for
I am writing a desktop and j2me application. I have debug statements in program.
I have two if statements in my code, what can I do so that
I have many MySQL statements that are running under MySQL 4, but not MySQL

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.