我有SQL:爲什麼 '由序' 慣於此SQL statament正確
SELECT t.TagText, COUNT(*) AS NumVidsWithTag
FROM tbl_Tag t
INNER JOIN tbl_Video_Tag_Xref x ON t.TagId=x.TagId
INNER JOIN tbl_Video v ON x.VideoId=v.VideoId
WHERE 6 IS NULL OR EXISTS (SELECT * FROM tbl_Video_Tag_Xref WHERE VideoId=6 AND TagId=t.TagId)
GROUP BY t.TagText
將返回:
1 1
10 1
11 1
12 1
13 1
14 1
15 1
16 1
17 1
18 1
19 1
2 1
20 1
然後,我改變了SQL來
SELECT t.TagText, COUNT(*) AS NumVidsWithTag
FROM tbl_Tag t
INNER JOIN tbl_Video_Tag_Xref x ON t.TagId=x.TagId
INNER JOIN tbl_Video v ON x.VideoId=v.VideoId
WHERE 6 IS NULL OR EXISTS (SELECT * FROM tbl_Video_Tag_Xref WHERE VideoId=6 AND TagId=t.TagId)
GROUP BY t.TagText
ORDER BY t.TagText ASC
它仍然回來爲:
1 1
10 1
11 1
12 1
13 1
14 1
15 1
16 1
17 1
18 1
19 1
2 1
20 1
我很困惑,爲什麼這不會正確排序?
p.s video id只是一個被替換的paramteer! – Exitos 2011-04-21 09:49:55
爲什麼名稱是「TagText」而不是「TagNumber」? :) – 2011-04-21 10:12:09