我有兩個表(學生帳戶)
每個學生都有學生表中的一個記錄,但是可能會在帳戶表
我需要總結的帳戶表一列多條記錄,由學生代碼分組學生表
如何彙總連接表中的列?
我寫了下面的查詢,但是當我使用GROUP BY命令,它已經返回了一個錯誤:
select students.id,students.stcode,students.stname,account.stcode,
sum(cast ((account.price) AS INT)) OVER() AS PriceTotal
from students
inner join account on students.stcode=account.stcode
group by students.stcode
錯誤消息:
Column 'students.id' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause
。
(1)這是mistagged的MySQL。這是其他一些RDMS。 (2)錯誤信息解釋你做錯了什麼。如果您不明白錯誤消息,請閱讀「GROUP BY」。 –
我在查詢中看不到'students.id'。查詢是最新的嗎? –