mysql计数查询

发布于 2025-02-01 05:23:32 字数 688 浏览 3 评论 0 原文

尽管我仍在尝试弄清楚这一点,但我想看看您对我的代码的反馈,以及您是否可以帮助我。我仍在尝试掌握mysql的概念,因此对任何帮助都非常感谢! 我正在运行MySQL作为人力资源

问题要求如下:

写SQL语句,以返回每个员工人数 薪水超过6000的部门。请勿退还 平均工资超过9000

的部门

是我的代码(不起作用)

SELECT DEPARTMENT_ID, 
       SALARY, 
       COUNT(*) 
FROM EMPLOYEES 
GROUP BY DEPARTMENT_ID
WHERE salary BETWEEN 6000 AND 9000;

我的代码(不起作用)我的错误消息:在关键字“ Where'的关键字附近的语法) 。 ///gyazo.com/2300fbfbf0b0b0eb0eb0ebbbb43294d594d59994d59994276E276E276E276E2555555555555555555559-APH555555555559APAR LTLT;

https :

whilst I'm still trying to figure this one out I'd like to see your feedback on my code and if you could help me. I'm still trying to grasp the concept of MySQL so any help is much appreciated! I'm running MySQL as an HR

The question requirement is as follows:

Write SQL statement that return the number of employees in every
department whose salary is more than 6000. Do not return the
department where the average salary is more than 9000

Below is my code (It doesn't work)

SELECT DEPARTMENT_ID, 
       SALARY, 
       COUNT(*) 
FROM EMPLOYEES 
GROUP BY DEPARTMENT_ID
WHERE salary BETWEEN 6000 AND 9000;

My error message: Incorrect syntax near the keyword 'WHERE'.
https://gyazo.com/2300fbf0b0ebb43294d599cee276e235 <-- Expected output

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

葬﹪忆之殇 2025-02-08 05:23:32

写SQL语句,以返回每个员工人数
薪水超过6000的部门。请勿退还
平均工资超过9000

的部门

每个部门的员工人数--- count(lightee_id)

工资
超过6000 ---薪水&gt; 6000

不要返回
平均工资超过9000 --- AVG(工资)的部门
&lt; = 9000

这将由:

SELECT DEPARTMENT_ID,
       COUNT(EMPLOYEE_ID) as nr_count
FROM   EMPLOYEES 
WHERE SALARY > 6000
GROUP BY DEPARTMENT_ID
HAVING AVG(SALARY) <=9000;

Write SQL statement that return the number of employees in every
department whose salary is more than 6000. Do not return the
department where the average salary is more than 9000

number of employees in every department --- count(EMPLOYEE_ID)

salary
is more than 6000 --- WHERE SALARY >6000

Do not return the
department where the average salary is more than 9000 ---avg(salary)
<=9000

This would be done by:

SELECT DEPARTMENT_ID,
       COUNT(EMPLOYEE_ID) as nr_count
FROM   EMPLOYEES 
WHERE SALARY > 6000
GROUP BY DEPARTMENT_ID
HAVING AVG(SALARY) <=9000;

https://dbfiddle.uk/?rdbms=mysql_8.0&fiddle=6165323c01f188bb0dbb8e6227bac7bc

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文