select E.Job_ID, count(*), max(Employee_Salary) as kos, avg(Employee_Salary)
from Employee E
inner join JOB D on E.Job_ID = D.Job_ID
group by E.Job_ID
我想通过D.Functio订购我的结果,但我有这个错误
Msg 8120, Level 16, State 1, Line 1
Column 'JOB.Functio' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
答案 0 :(得分:2)
有关错误消息的不清楚之处?您正尝试通过未聚合的内容进行排序。这是一个解决方案:
order by max(d.Functio)
问题是别名“作业”未知。您需要使用分配给表格的“d”。
这应该有用,因为大概有一个job.Functio每个工作ID。另一个解决方法是将group by
更改为:
group by e.Job_ID, d.Job.Functio
答案 1 :(得分:1)
如果它是描述性列(作业函数?)
,您想将它添加到GROUP BYselect E.Job_ID, count(*), max(Employee_Salary) as kos, avg(Employee_Salary)
from Employee E
inner join JOB D on E.Job_ID = D.Job_ID
group by E.Job_ID, D.Functio
order by D.Functio
否则在订购中你需要应用聚合函数,如min(),max(),avg()等。
答案 2 :(得分:1)
在D.Functio
和Select
Group by
select E.Job_ID, D.Functio,
count(*), max(Employee_Salary) as kos, avg(Employee_Salary)
from Employee E
inner join JOB D on E.Job_ID = D.Job_ID
group by E.Job_ID, D.Functio
order by D.Functio