I have a Database with salary values of specific job types and am trying to get an output that separates the job, the amount of jobs with salary info given, and then the amount of jobs above a certain salary limit.
SELECT * FROM
(SELECT job_list_name, COUNT(job_list_name) FROM Jobs_Salaries
WHERE salary_range_low = "100K+" OR salary_range_low = "125K+"
OR salary_range_low = "150K" OR salary_range_low = "200K+") AS t1
INNER JOIN
(SELECT job_list_name, COUNT(job_list_name) FROM Jobs_Salaries
WHERE indeed_salary != "None") AS t2
ON t1.job_list_name = t2.job_list_name
GROUP BY t1.job_list_name
ORDER BY COUNT(t2.job_list_name) DESC;
This is what I currently have yet my output is this:
MACHINE LEARNING ENGINEER|178
DATA ENGINEER|148
DATA SCIENTIST|122
DATA ANALYST|15
MACHINE LEARNING ENGINEER|241
DATA ANALYST|224
DATA ENGINEER|219
DATA SCIENTIST|187
DATA ANALYST|463|DATA ANALYST|871
the values above the last data analyst value being the separate outputs of each statement but I'm not sure why that last value is there. I'm trying to achieve an output like this:
Job Type # of Jobs with Salary Values # of Jobs above $100k
DATA ENGINEER 400 150
DATA ANALYST 300 100
DATA SCIENTIST 200 125
MACHINE LEARNING ENGINEER 100 100
With the values separated by the counts of each SELECT statement and being grouped by the Job Title. Any help is appreciated!
Consider conditional aggregation by moving WHERE
conditions to aggregated SELECT
columns:
SELECT job_list_name,
SUM(indeed_salary != 'None') AS [# of Jobs with Salary Values],
SUM(salary_range_low IN ('100K+', '125K+', '150K', '200K+')) AS [# of Jobs above $100k]
FROM Jobs_Salaries
GROUP BY job_list_name
ORDER BY COUNT(t2.job_list_name) DESC;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.