[英]Sql AVG included but getting Column is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause
[英]Column 'Tabel1.Nama' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause
“Tabel1.Nama”列在 select 列表中無效,因為它不包含在聚合 function 或 GROUP BY 子句中。
我有兩個表,表 1
和表 2
我想像這樣展示
我的查詢:
SELECT Tabel1.NIK, Tabel1.Nama, AVG(Table2.Nilai) AS RataRata FROM
Tabel1, Table2 WHERE Tabel1.NIK = Table2.NIK GROUP BY Tabel1.NIK
但我有這樣的錯誤 Column 'Tabel1.Nama' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
任何人都可以修復我的查詢?
通過以下方式將 Nama 添加到組中
SELECT Tabel1.NIK, Tabel1.Nama, AVG(Table2.Nilai) AS RataRata FROM Tabel1, Table2 WHERE Tabel1.NIK = Table2.NIK GROUP BY Tabel1.NIK, Tabel1.Nama
或者從 select 中刪除 Nama
SELECT Tabel1.NIK, AVG(Table2.Nilai) AS RataRata FROM Tabel1, Table2 WHERE Tabel1.NIK = Table2.NIK GROUP BY Tabel1.NIK
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.