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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:42:22+00:00 2026-05-28T05:42:22+00:00

I need to get two summations in the same query based on different criteria.

  • 0

I need to get two summations in the same query based on different criteria. Both criteria operate on the same column.
Is there a way to do this?

I can best explain this with an example:

Table :
salary_survey_result

Columns:
industry,
location,
position,
salary

Effectively I want to combine the following two queries:

SELECT industry, location, count(*) as MORE_THAN_SIX_FIGURE   
FROM salary_survey_result  
WHERE salary > 100000  
GROUP BY industry, location

and

SELECT industry, location, count(*) as MORE_THAN_FIVE_FIGURE  
FROM salary_survey_result  
WHERE salary > 10000  
GROUP BY industry, location

So the result is something like this:
industry location MORE_THAN_FIVE_FIGURE MORE_THAN_SIX_FIGURE


Healthcare    NY               45                      10  
Healthcare    MN               35                       6   
InfoTech      NY               50                      19
InfoTech      MN               40                      12
  • 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-05-28T05:42:22+00:00Added an answer on May 28, 2026 at 5:42 am

    Something like

    SELECT industry, 
           location, 
           sum( case when salary >= 10000 then 1 else 0 end) as MORE_THAN_FIVE_FIGURE,
           sum( case when salary >= 100000 then 1 else 0 end) as MORE_THAN_SIX_FIGURE
      FROM salary_survey_result  
      WHERE salary >= 10000  
      GROUP BY industry, location
    

    The WHERE salary >= 10000 clause isn’t necessary for the results. It may improve performance if there is an index on SALARY and most salary values are less than 10000. Note that I’m also assuming that you meant >= rather than > since a salary of 10,000 is a five figure salary.

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

Sidebar

Related Questions

Trying to get two different counts in one query. To do this I am
I get two strings formated like (Brazilian Format): DD/MM/YYYY, I need to compare both.
I have two numbers, and need to get returned the lower one. Is there
Currently I need to run two queries to get both the total amount of
Ok, I have a query over two tables. I need to get two sums.
I need to get two JPanels into one JApplet. paneel = new RekenmachinePaneel(); nummer
I have two tables with a weak relation. I need get a text value
I need to get the biggest value from two fields: SELECT MAX(field1), MAX(field2) Now,
I am starting a project in which I need to get two sets of
I have two combobox. I need get some value from first combobox1 after combobox1

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.