UPDATE a_timeblock SET timeblock_due_date=DATE(timeblock_next_update),
CASE timeblock_recurrence_unit
WHEN day THEN
DATE_ADD(NOW(),INTERVAL timeblock_recurrence_time day )
WHEN month THEN
DATE_ADD(NOW(),INTERVAL timeblock_recurrence_time month)
END
WHERE timeblock_recurrence=1 AND timeblock_complete=0 AND timeblock_next_update=
FROM_UNIXTIME(1337662800)
以上查询错误。我想做上面这样的事情。如果可能,我该怎么做。
#1064 - You have an error in your SQL syntax;
check the manual that corresponds to your MySQL
server version for the right syntax to use near
'CASE timeblock_recurrence_unit WHEN 'day' THEN DATE_ADD(NOW(),IN' at line 2
答案 0 :(得分:1)
您的第二个值没有目标列。
UPDATE a_timeblock
SET timeblock_due_date = DATE(timeblock_next_update),
column_name? = CASE ... END
WHERE ...
答案 1 :(得分:0)
我认为您需要在案例中使用引号并简单地设置timeblock_due_date
:
...
SET timeblock_due_date =
CASE timeblock_recurrence_unit
WHEN 'day' THEN
DATE_ADD(NOW(),INTERVAL timeblock_recurrence_time day )
WHEN 'month' THEN
DATE_ADD(NOW(),INTERVAL timeblock_recurrence_time month)
END
...
这假定timeblock_recurrence_unit
是VARCHAR
类型(需要它)
答案 2 :(得分:0)
这样的事可能吗?
UPDATE a_timeblock SET timeblock_due_date=
CASE timeblock_recurrence_unit
WHEN 'day' THEN
DATE_ADD(NOW(),INTERVAL timeblock_recurrence_time day )
WHEN 'month' THEN
DATE_ADD(NOW(),INTERVAL timeblock_recurrence_time month)
END
WHERE timeblock_recurrence=1 AND timeblock_complete=0 AND timeblock_next_update=
FROM_UNIXTIME(1337662800)