我想從SQL Server數據庫顯示唯一的行。我有兩個名爲UploadedData
和DummyReportDetail
的表格。我想加入這些表格,但我沒有使用獨特的獨特行。SQL Server中的唯一行
這是我的查詢:
SELECT DISTINCT
D.TokenNo, D.UploadDate AS "Date", D.[Time],
D.SMSContent AS [Message], D.SMSType AS [SMS Type],
(SELECT COUNT(d.MobNo) FROM dbo.DummyReportDetail AS d
WHERE d.UploadDate = '31/12/2012' AND d.UserID = '2'
AND d.UserType = 'Reseller' AND d.TokenNo = U.TokenNo) AS "Count",
D.DStatus AS "Status"
FROM
dbo.DummyReportDetail AS D
INNER JOIN
dbo.UploadedData AS U ON D.TokenNo = U.TokenNo
WHERE
D.UploadDate = '31/12/2012' AND D.UserID = '2'
AND D.UserType = 'Reseller' AND D.TokenNo = U.TokenNo
ORDER BY
D.TokenNo DESC
我的這個查詢的輸出是:
Token-4 31/12/2012 11:23:59 AM संपादकीय Unicode 2 SUBMITED
Token-4 31/12/2012 11:24:9 AM संपादकीय Unicode 2 SUBMITED
Token-3 31/12/2012 10:21:31 AM TestSMS Normal 1 SUBMITED
但我想這樣的輸出:
Token-4 31/12/2012 11:24:9 AM संपादकीय Unicode 2 SUBMITED
Token-3 31/12/2012 10:21:31 AM TestSMS Normal 1 SUBMITED
請幫我... 在此先感謝
你在輸出中得到的那三行是**不是**重複的 - 它們在不同的列上有所不同 - 這就是爲什麼DISTINCT不能擺脫它們的原因...... –