gpt4 book ai didi

mysql - 嵌套查询的问题

转载 作者:行者123 更新时间:2023-11-29 22:24:11 27 4
gpt4 key购买 nike

嘿伙计们,我一直在研究这个问题,但我无法解决它。有人可以帮我解决这个问题吗?我尝试了很多方法但无法解决它,任何人都可以通过使用嵌套查询并仅使用(GROUP BY、HAVING、SELECT、FROM 和 WHERE)来帮助我

(Qs)You would like to know the departments with more than 5 full-time young employees (Age <25) each department has. Calculate the average salary of the employees who work for those departments. This newly calculated field should be named as "AvgSalary" and be returned by your query.

这是其架构。

Employee(EmployeeID: Integer, EmpName: String, Age: Integer, Salary: Real)  
Department(DeptID: Integer, DeptName: String, Budget: Real, ManagerID: Integer)
Works(EmployeeID: Integer, DeptID: Integer, Percent_Time: Integer)

最佳答案

如果您只对目标群体(25 岁以下)的平均工资感兴趣,则不需要嵌套...

SELECT d.*
, AVG(********) AvgSalary
FROM ********
JOIN ********
ON ******** = ********
JOIN ********
ON ******** = ********
WHERE ******** = 100
AND ******** < 25
GROUP
BY ********
HAVING COUNT(*) > 5;

如果您需要目标组返回的部门内所有员工的平均工资,那么您可以使用子查询,但我会使用 CASE 语句,

关于mysql - 嵌套查询的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30418080/

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