我試圖運行查詢聯接和集團不同:選擇與
Select Distinct table2.columnA columnA_0 ,
table3.columnB columnB_1 ,
table2.columnC columnC_2
From table4 Join table1 on table4.columnD = table1.columnD
Left Outer Join table2 on table2.columnD = table1.columnD
Left Outer Join table3 on table3.columnE = table2.columnE
where table2.columnA IS NOT NULL
group by dbo.table2.columnA
但我收到錯誤
Column 'table3.columnB' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause
誰能告訴我爲什麼?
爲什麼你使用'distinct'和'group by'?如果選擇列表中的所有列不在聚合函數中,則SQL Server會要求所有列位於一個組中。刪除組。 – Taryn
如果您不使用聚合,羣組的意圖是什麼? – bummi