我無法弄清楚爲什麼會發生這種情況。下面的MySQL查詢返回了我49行,但「總」,在每個排在下面的代碼運行時顯示爲48.MySQL SELECT DISTINCT返回不同的結果
SELECT DISTINCT t2.CIN, t1.Name,
(SELECT COUNT(DISTINCT CIN) FROM `cSignatoryAssociations` WHERE DIN ='00016902') As Total
FROM `cSignatoryAssociations` t2
LEFT JOIN `cRoC` t1 ON t1.CIN = t2.CIN
WHERE t2.DIN='00016902'
ORDER BY SUBSTRING(t1.CIN,9,4) DESC;
分開我得到預期的結果,即49
SELECT COUNT(DISTINCT CIN) FROM `cSignatoryAssociations` WHERE DIN ='00016902'
請幫我指點迷津出了什麼問題。
'DISTINCT t2.CIN,t1.Name'與'DISTINCT t2.CIN'有所不同 –
是的,因爲對於每一行,您都會一次又一次地計算相同的事物。 –