简体   繁体   English

具有avg和count大于值的MySQL查询

[英]MySQL query with avg and count greater than a value

I have table tbl_emply containing fields Salary , DNO , and EID for each employ. 我有表tbl_emply包含每个雇员的字段SalaryDNOEID I need to find average Salary of each DNO that has more than two employees. 我需要找到每个拥有两名以上员工的DNO的平均薪资

表内容

I have tried queries like 我试过像

  1.  select avg(salary),DNO from tbl_emply where count(select * from tbl_emply group by(DNO)>2); 
  2.  select avg(salary),DNO from tbl_emply group by(DNO); 

But these all gave me invalid use of group by. 但这些都让我无效地使用了group by。 How to get the result? 如何获得结果?

Use HAVING 使用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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM