2017-09-05 58 views
3

更大我有表tbl_emply包含字段工資DNO,併爲每個僱用EID。我需要找到平均值薪水每個DNO有超過兩名僱員。MySQL查詢與平均和計數比的值

Table Contents

我已經嘗試了查詢,如

  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); 
    

但是所有這些都給我無效使用組通過。如何獲得結果?

回答

4

使用HAVING

SELECT AVG(salary), DNO 
FROM tbl_emply 
GROUP BY DNO 
HAVING COUNT(*) > 2 
0

試試這個,

select avg(Salary),DNo from tbl_emply group by DNo having count(*)>2;