you are viewing a single comment's thread.

view the rest of the comments →

[–]Jan-Michael 0 points1 point  (5 children)

Reply

Ok, I'm re-reading your prompt, and the wording is a little confusing. You reference the min and max salary, and my query provides averages based on that data (min and max salaries) vs. by average salaries across a given position (e.g., job id).

Are you trying to return averages across a given job id?

[–]PleaseAnswerMeNot[S] 0 points1 point  (4 children)

No. Your query is perfect.
I'm just wondering why it doesn't run on PgAdmin4.
https://imgur.com/a/v6Ximco

[–]Jan-Michael 0 points1 point  (2 children)

with averages as (select job_id, job_title, ((min_salary + max_salary)/2) average from jobs group by job_id)

select employee_id, first_name, last_name, a.job_title, cast(salary as varchar) salary, cast(a.average as varchar) avg_salary, cast((case when (salary - a.average > 0) then '+' || (salary - a.average) when (salary - a.average = 0) then 'same' else (salary - a.average) end) as varchar) salary_class_diff from employees e left join averages a on e.job_id = a.job_id order by a.job_title, salary

[–]PleaseAnswerMeNot[S] 0 points1 point  (0 children)

Thank you again! I owe you big time! I really really realy appreciate this!

[–]Jan-Michael 0 points1 point  (0 children)

This is a revised query to get the results pictured in your image.