我收到一个错误 - 选择列表中的列“Employee.EmpID”无效,因为它不包含在聚合函数或 GROUP BY 子句中。select loc.LocationID, emp.EmpIDfrom
我收到一个错误 -
选择列表中的列“Employee.EmpID”无效,因为它不包含在聚合函数或 GROUP BY 子句中。
select loc.LocationID, emp.EmpID
from Employee as emp full join Location as loc
on emp.LocationID = loc.LocationID
group by loc.LocationID
这种情况与Bill Karwin给出的答案相符。
上述修正,符合 ExactaBox 的回答 -
select loc.LocationID, count(emp.EmpID) -- not count(*), don't want to count nulls
from Employee as emp full join Location as loc
on emp.LocationID = loc.LocationID
group by loc.LocationID
原始问题 -
对于 SQL 查询 -
select *
from Employee as emp full join Location as loc
on emp.LocationID = loc.LocationID
group by (loc.LocationID)