1
大家好我有一個SQL查詢的問題:問題是,如果我添加GROUP BY
數據庫引擎輸出錯誤:錯誤查詢:聚合函數或GROUP BY子句
Column 'dbo.classes.class_name' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
我的查詢:
string query = "SELECT p.*
FROM dbo.classes AS p INNER JOIN teacher_classes AS a
ON a.class_id = p.class_id
and teach_id = @id
GROUP BY p.class_id";
請問有沒有什麼幫助。
注意沒有分組的查詢工作正常,但結果沒有分組。
你在分組什麼?你想要實現什麼業務邏輯? GROUP BY子句只需要像COUNT或SUM這樣的聚合函數,顯然你的查詢缺乏, – APC