我正在尝试选择一条记录的记录,其中记录的日期字段是当前日期+ 7天
我以前是这样在MySQL中这样做的:
SUM(CASE WHEN ( d.next_date + INTERVAL 7 DAY) THEN 1 ELSE 0 END) AS dateCount
但是现在尝试在DB2上执行此操作不起作用
SUM(case WHEN f.next_date + 7 days then 1 else 0 end) as dateCount
我想知道为什么会这样,但是我只是想对日期为今天+ 7天的所有记录进行计数。
我在做什么错
答案 0 :(得分:1)
您的案例表达式缺少比较,例如when (some_value is compared to other_value) then do_something ...
。也许相等?
SUM(case when {date field of the record} = f.next_date + 7 days then 1 else 0 end) as dateCount
答案 1 :(得分:0)
尝试一下:
select sum(case when f.next_date = current date + 7 day then 1 end) as dateCount
from table(values
current date + 1 day
, current date + 7 day
, current date + 7 day
) f(next_date);