I have table tbl_emply containing fields Salary , DNO , and EID for each employ. I need to find average Salary of each DNO that has more than two employees.
I have tried queries like
select avg(salary),DNO from tbl_emply where count(select * from tbl_emply group by(DNO)>2);
select avg(salary),DNO from tbl_emply group by(DNO);
But these all gave me invalid use of group by. How to get the result?
Use HAVING
SELECT AVG(salary), DNO
FROM tbl_emply
GROUP BY DNO
HAVING COUNT(*) > 2
试试这个,
select avg(Salary),DNo from tbl_emply group by DNo having count(*)>2;
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.