select t.acno,t.name,count(Q.trans) as test,Q.transvalue,q.transdate
from dbo.test t
inner join dbo.testaqc q
on t.acno=Q.acno
group by q.trans
加入與組兩個表,但我收到的錯誤:
Msg 8120, Level 16, State 1, Line 1 Column 'dbo.test.acno' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
將其包含在一個聚合函數中或將其添加到group by子句中。這是一個非常有用的錯誤消息。您選擇的其他列(名稱,轉換值,轉換表)也是如此,這些列未彙總或分組。 –
你谷歌這個錯誤?這是一個非常常見的錯誤,你可以很容易地得到答案。 -1。當您在谷歌搜索錯誤時,只使用錯誤代碼和/或錯誤信息。不要使用列名等。例如。列在選擇列表中無效,因爲它不包含在聚合函數或GROUP BY子句中。 – Steam
查看Bill karwins的答案在這裏 - http://stackoverflow.com/questions/13999817/reason-for-column-is-invalid-in-the-select-list-because-it-is-not-contained-in-e它通過一個簡單的例子告訴你錯誤的原因,而不僅僅是如何糾正錯誤,並讓你的查詢運行。 – Steam