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

标签 asp.net sql error-handling group-by

代码出错... 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/

相关文章:

asp.net - specflow 的 .msi 安装程序和它的 nuget 包之间有什么区别吗?

mysql - 在 Mysql 中更新表的属性时触发

sql - 异步服务器,在等待回调时处理断开连接

sql - "Flexible"(?) Rails 数据库

javascript - jQuery $ .ajax发布获取引荐来源网址以进行错误调试

r - tryCatch在for循环中

.net - IIS7 下超出 Web 配置大小限制 0x80070032

asp.net - ASP .NET AJAX 和 JQuery

asp.net - 是否有一个asp :Wizard have to output a html table? 我希望它输出一个简单的div标签

php - 引用 - 这个错误在 PHP 中意味着什么?