gpt4 book ai didi

MySQL 查询 avg 和 count 大于一个值

转载 作者:可可西里 更新时间:2023-11-01 08:03:00 26 4
gpt4 key购买 nike

我有一个表 tbl_emply,其中包含每个雇员的字段 SalaryDNOEID。我需要找到每个拥有两个以上员工的 DNO 的平均薪水

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

但是这些都让我无效使用group by。如何得到结果?

最佳答案

使用HAVING

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

关于MySQL 查询 avg 和 count 大于一个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46057486/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com