sql server - How to get multiple average values using subqueries -


there many accountants , each of them has jobs (paid hour) , need accountant name of every accountant has average job cost higher overall average of job costs. how do this?

select accountant_name, avg(job_cost) 'average' job_view average > (select avg (job_cost) av job_view) group accountant_name; 

everything needed in view named job_view. above code not working on modifications appreciated. in advance.

this should you:

select accountant_name     , avg(job_cost) 'average' job_view group accountant_name having avg(job_cost) > (select avg(job_cost) job_view) 

as per comment, error you're getting @ where average > because alias average not visible in where clause , requires put entire contents of column defined in select part.

but because in select part average column aggregate function, these can go lower in having section, because having handles filtering of aggregate conditions.

why this? because there rules order of execution of statements in query, explained here.


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -