我有以下简单查询,显示valuehome
与el2
的总和。
如果我在我的查询中添加了另一列(请参阅select语句2),并说只显示valuehome
到期日在今天之前,即它已逾期,我在{{1}上丢失了我的总和}因为结果显示每个截止日期的行
如何保持valuehome
的总和,以便即使有多个截止日期,我也会看到valuehome
的一个结果。
valuehome
谢谢Nenad - 这是很棒的帮助 - 你知道我将如何在where语句中更改我的静态日期
不要向SELECT TOP (100) PERCENT el2, statpay, SUM(valuehome) AS Expr1
FROM dbo.MBO450
GROUP BY el2, statpay
HAVING (el2 LIKE 'C%') AND (statpay = 84)
ORDER BY el2
SELECT TOP (100) PERCENT el2, statpay, SUM(valuehome) AS Expr1, duedate
FROM dbo.MBO450
GROUP BY el2, statpay, duedate
HAVING (el2 LIKE 'C%') AND (statpay = 84) AND (duedate <= CONVERT(DATETIME, '2013-07-24 00:00:00', 102))
ORDER BY el2
和GROUP BY
添加duedate - 在分组前过滤WHERE条件中的行:
HAVING
以便静态日期是今天的日期?
答案 0 :(得分:0)
不要将duedate
添加到GROUP BY
和HAVING
- 在分组之前过滤WHERE
条件中的行:
SELECT el2, statpay, SUM(valuehome) AS Expr1
FROM dbo.MBO450
WHERE duedate <= CONVERT(DATETIME, '2013-07-24 00:00:00', 102))
GROUP BY el2, statpay
HAVING (el2 LIKE 'C%') AND (statpay = 84)
ORDER BY el2
PS:TOP (100) PERCENT
无用
PPS:您还可以将el2
和statpay
条件移至WHERE
PPPS:今天替换为WHERE duedate <= GETDATE()
动态