SQLTeam.com | Weblogs | Forums

Select distinct- New to sql and have some questions on my query

SELECT eq.emp3, eq.wages, eq.ave_wages,
CASE WHEN EQ.ave_wages = 0 THEN '0'
WHEN EQ.ave_wages BETWEEN 0 AND 500 THEN '0-500'
WHEN EQ.ave_wages BETWEEN 501 AND 1000 THEN '501-1000'
WHEN EQ.ave_wages BETWEEN 1001 AND 1500 THEN '1001-1500'
WHEN EQ.ave_wages BETWEEN 1501 AND 2000 THEN '1501-2000'
WHEN EQ.ave_wages BETWEEN 2001 AND 2500 THEN '2001-2500'
WHEN EQ.ave_wages BETWEEN 2501 AND 3000 THEN '2501-3000'
WHEN EQ.ave_wages BETWEEN 3001 AND 3500 THEN '3001-3500'
WHEN EQ.ave_wages BETWEEN 3501 AND 4000 THEN '3501-4000'
WHEN EQ.ave_wages BETWEEN 4001 AND 4500 THEN '4001-4500'
WHEN EQ.ave_wages BETWEEN 4501 AND 5000 THEN '4501-5000'
WHEN EQ.ave_wages BETWEEN 5001 AND 5500 THEN '5001-5500'
WHEN EQ.ave_wages BETWEEN 5501 AND 6000 THEN '5501-6000'
WHEN EQ.ave_wages BETWEEN 6001 AND 6500 THEN '6001-6500'
WHEN EQ.ave_wages BETWEEN 6501 AND 7000 THEN '6501-7000'
WHEN EQ.ave_wages BETWEEN 7001 AND 7500 THEN '7001-7500'
WHEN EQ.ave_wages >= 7500 THEN'7500+' END wage_range
FROM (SELECT DISTINCT eq.emp3,eq.wages,SUM(eq.emp1) emp1,SUM(eq.emp2) emp2,
SUM(eq.emp3) emp3, SUM(eq.wages) wages,ROUND(AVG(emp1 + emp2 + emp3) / wages) ave_wage
FROM owner.qui eq
WHERE eq.yrqtr = 20181
AND eq.meei != 2)

Okay my questions:
I want the average wages is this the correct way to do it? ROUND(AVG(emp1 + emp2 + emp3) / wages)

I also am getting an error on the EQ part of EQ.ave_wages, Do I need parenthesis somwhere and to rename it something else after select distinct?

Thanks for any help, I am newer to sql and this query is taking me forever to work out.