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_resultColumns:
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
Something like
The
WHERE salary >= 10000clause isn’t necessary for the results. It may improve performance if there is an index onSALARYand 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.