这个查询到底有什么问题?
SELECT id,
SUM(CASE myDate
WHEN DATEDIFF(day, myDate, GETDATE()) = 0 THEN [Items]
ELSE 0
END)
FROM myTable
GROUP BY id
???
错误说
"Incorrect syntax near '='.
这个查询到底有什么问题?
SELECT id,
SUM(CASE myDate
WHEN DATEDIFF(day, myDate, GETDATE()) = 0 THEN [Items]
ELSE 0
END)
FROM myTable
GROUP BY id
???
错误说
"Incorrect syntax near '='.
这是您想要的查询:
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
.
SELECT id, SUM(CASE myDate WHEN DATEDIFF(day, myDate, GETDATE() = 0) THEN [Items] ELSE 0 END) 从 myTable GROUP BY id
这是对的
你不需要mydate
之后CASE
SELECT id,
SUM(CASE
WHEN DATEDIFF(day, myDate, GETDATE()) = 0
THEN [Items] ELSE 0 END)
FROM myTable GROUP BY id;
SUM(CASE myDate WHEN DATEDIFF(day, myDate, GETDATE()) )
我猜你错过了一个封闭的括号