我寫了一個查詢像如何在SQL Server 2008中顯示一個月的所有日子?
SELECT
Sum(a.in_total) as Totall,
DATEPART(dd, a.in_date_issued) as dateissued
FROM
dbo.IN_Invoices as a
WHERE
DATEPART(mm, a.in_date_issued) = 5
AND DATEPART(yyyy, a.in_date_issued)= 2015
AND a.sy_id='DPI'
AND EXISTS(SELECT DISTINCT cl_id as clid
FROM dbo.cloi_clientorderitems as c
WHERE c.masterorderid=a.masterorderid)
--AND c.cl_id NOT IN ('100001_DPO'))
GROUP BY
DATEPART(dd, a.in_date_issued)
ORDER BY dateissued ASC
這個查詢將寫入了讓像
Total| day
100 | 1
0 | 3
150 | 10
-
-
200 | 31
預計輸出
Total| day
100 | 1
150 | 2
0 | 3
600 | 4
-
-
200 | 31
請幫我在該查詢。
當你使用'GROUP BY DATEPART(DD,a.in_date_issued)'你一定會還'ORDER BY DATEPART(DD,a.in_date_issued)asc'?嘗試一下,讓我知道。 –
沒有相同的結果..沒有得到預期的結果,因爲我顯示 –
啊,好吧。這是在黑暗中拍攝的。我對sql-server做的這麼少,以至於超出了我的經驗範圍。 –