gpt4 book ai didi

asp.net - 由于group by子句,撤消无效错误

转载 作者:行者123 更新时间:2023-12-03 08:56:23 25 4
gpt4 key购买 nike

代码出错... Staff.StaffId/Name总是被指出为错误。
想要选择职员ID,anem和服务年限,条件是主管ID = 7并且“服务年限” <10

Column 'Staff.Name' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.


select staffId,Name, DATEDIFF(year,DateJoin,GETDATE()) as 'Years in Service' from Staff
JOIN Branch ON Branch.BranchNo=Staff.BranchNo
where SupervisorID=7
having COUNT(*) <10

最佳答案

最简单的解决方法是将Group By子句添加到函数中。尝试:

select staffId,Name, DATEDIFF(year,DateJoin,GETDATE()) as 'Years in Service' from Staff
JOIN Branch ON Branch.BranchNo=Staff.BranchNo
where SupervisorID=7
GROUP BY staff.name, staff.staffId
having COUNT(*) <10

关于asp.net - 由于group by子句,撤消无效错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24025565/

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