我要帶兩個下面的語句,只得到了結果於2013年限制SQL語句年
SELECT
COUNT(DISTINCT
CAST(c1.caseseqnumber AS VARCHAR) + '-' + CAST(c1.year AS VARCHAR)),
COUNT(DISTINCT
CAST(c2.caseseqnumber AS VARCHAR) + '-' + CAST(c2.year AS VARCHAR))
FROM
caseparticipants c1 LEFT JOIN caseparticipants c2
ON c1.year=c2.year AND c1.caseseqnumber=c2.caseseqnumber
AND c2.participanttype = 'Appellant Rep 1'
和第二個
SELECT DISTINCT
c1.caseseqnumber,
c1.year
FROM
caseparticipants c1 LEFT JOIN caseparticipants c2
ON c1.year=c2.year AND c1.caseseqnumber=c2.caseseqnumber
AND c2.participanttype = 'Appellant Rep 1'
WHERE
c2.year IS NULL
Order by year ASC, Caseseqnumber ASC
謝謝!
你嘗試過什麼?我看到「WHERE c2.year IS NULL」,所以這不會那麼困難。 – 2013-05-02 14:21:44
當我嘗試它刪除所有正確的結果。如果我做c2.year ='2013'我沒有得到我需要的結果集 – parkjohnston 2013-05-02 14:22:33
沒錯,但我們不知道你得到了什麼結果集,以及你在找什麼。不確定任何人都可能提供幫助。 – 2013-05-02 14:23:37