mysql - sql query for a certain condition -


i have table like:

empid empsalary empdept 1   45000   2   40000   3   50000   sales 4   60000   sales 5   75000   6   80000   7   25000   ops 8   30000   ops 9   55000   marketing 10  60000   marketing 

i have write query as:

select empid empsalary  > avg(empsalary) each  empdept 

kindly help.

try this:

select e.empid, e.empsalary, e.empdept   employee e  inner join (select e1.empdept, avg(e1.empsalary) empsalary              employee e1              group e1.empdept            ) on e.empdept = a.empdept , e.empsalary > a.empsalary; 

edit

select e.empdept, count(distinct e.empid) noofemployees employee e  inner join (select avg(e1.empsalary) empsalary employee e1) on e.empsalary > a.empsalary group e.empdept; 

Comments

Popular posts from this blog

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -