【发布时间】:2016-11-09 17:43:14
【问题描述】:
我正在尝试过滤掉特定用户添加的结果,同时保留每一天,因为此查询将用于报告中的图表。当我删除 t2.createdBy <> 21 时,我得到了所有的日期,但我还需要通过它过滤的结果是正确的。
查询:
SELECT
t1.DateFull, COUNT(t2.ContainerWashedDate) as Washes
FROM
DateLookup t1
LEFT JOIN
factContainerWash t2 ON t1.Datefull = t2.ContainerWashedDate
WHERE
(t1.DateFull >= '10/5/2016')
AND (t1.DateFull <= '11/9/2016')
AND t2.createdBy <> 21
GROUP BY
t1.DateFull
ORDER BY
DateFull
结果:
DateFull | Washes
-------------------------+-------
2016-10-05 00:00:00.000 | 1231
2016-10-06 00:00:00.000 | 466
2016-10-10 00:00:00.000 | 84
2016-10-12 00:00:00.000 | 75
预期结果:
DateFull | Washes
-------------------------+-------
2016-10-05 00:00:00.000 | 1231
2016-10-06 00:00:00.000 | 466
2016-10-07 00:00:00.000 | 655
2016-10-08 00:00:00.000 | 23
【问题讨论】:
-
但是
createdBy不可能是 21,如果它根本不存在的话。你有一个逻辑问题需要首先解决。
标签: sql-server tsql reporting-services ssrs-2008