这个查询的狄更斯出了什么问题?
SELECT id,
SUM(CASE myDate
WHEN DATEDIFF(day, myDate, GETDATE()) = 0 THEN [Items]
ELSE 0
END)
FROM myTable
GROUP BY id
???
错误说
"Incorrect syntax near '='.
答案 0 :(得分:0)
SUM(CASE myDate WHEN DATEDIFF(day, myDate, GETDATE()) )
你错过了一个封闭的支架我想
答案 1 :(得分:0)
这是您想要的查询:
SELECT id,
SUM(CASE WHEN DATEDIFF(day, myDate, GETDATE()) = 0 THEN [Items] ELSE 0 END)
FROM myTable
GROUP BY id;
myDate
之后的case
没有为您做任何事情。语法上允许case
语句的替代形式:
sum(case mydate when '2013-01-01' then 'New Years Day' . . .
但是当你在when
之后有一个表达时。
答案 2 :(得分:0)
mydate
CASE
SELECT id,
SUM(CASE
WHEN DATEDIFF(day, myDate, GETDATE()) = 0
THEN [Items] ELSE 0 END)
FROM myTable GROUP BY id;
答案 3 :(得分:0)
SELECT id, SUM(CASE myDate 当DATEDIFF(day,myDate,GETDATE()= 0)那么[Items] ELSE 0 结束) 来自myTable GROUP BY id
这是正确的