任何人有任何想法可以更好地寫這段代碼?寫更好的方法:SELECT * COUNT> 1
SELECT Column_A, Column_B, Column_C, Column_D, Column_E
FROM TABLE_A
WHERE Column_A IN
(
SELECT Column_A
FROM
(
SELECT Column_A, COUNT(DISTINCT COLUMN_B) AS Column_B_Count
FROM TABLE_A
GROUP by Column_A
HAVING Column_B_Count > 1
) AS A
)
GROUP BY Column_A, Column_B, Column_C, Column_D, Column_E;
謝謝!
無論何時您選擇GROUP BY時,您選擇的每一列其實都意味着'DISTINCT',儘管在5列開始看起來很可疑。您可以在'HAVING'子句之後放置聚合函數(如'COUNT'),這意味着您可以從'SELECT'列表中移除它並擺脫中間子查詢。除此之外,我們需要更多關於您的表格/數據的信息。 –