日期:2014-05-17 浏览次数:20529 次
SELECT a.[date], num=SUM((CASE WHEN B.[date] IS NULL THEN 0 ELSE 1 END)) --注意:你的计算方式可能要变
FROM
(
SELECT [date]=CONVERT(CHAR(10),DATEADD(DAY,-number,GETDATE()),120) FROM master..spt_values
WHERE [type] = 'p' AND number < 7
) a
LEFT JOIN youtablename B
ON a.[date] = CONVERT(CHAR(10), B.[date], 120)
GROUP BY a.[date]