我正在尝试按照this SO thread
给出的格式从UPDATE
开始SELECT
它不起作用。我想知道是不是因为我在执行计算时需要一个不同的UPDATE ... SELECT结构。
我尝试了以下各种版本:
UPDATE tbl_usertime uat
SET uat.delay_qual = (TIMESTAMPDIFF(MINUTE, uat.view_date, '2011-10-11 15:22:25') > adt.delay),
freq_qual = (adt.frequency > uat.imps_today)
FROM tbl_timing adt
JOIN tbl_usertime uat
ON uat.ad_id = adt.ad_id;
...但是它返回'SQL语法中的错误...附近'FROM tbl_timing adt JOIN tbl_usertime uat'
有什么想法吗? 谢谢!
答案 0 :(得分:2)
MySQL语法略有不同,试试这个:
update tbl_usertime uat join tbl_timing adt on uat.ad_id=adt.ad_id set
uat.delay_qual = (TIMESTAMPDIFF(MINUTE, uat.view_date, '2011-10-11 15:22:25') > adt.delay),
freq_qual = (adt.frequency > uat.imps_today)
答案 1 :(得分:1)
我不确定它是否有效,但阅读MySQL文档给我的印象可能是有效的:
UPDATE tbl_usertime join tbl_timing
SET tbl_usertime.delay_qual = (TIMESTAMPDIFF(MINUTE, tbl_usertime.view_date, '2011-10-11 15:22:25') > tbl_timing.delay),
freq_qual = (tbl_timing.frequency > tbl_usertime.imps_today)
where
tbl_usertime.ad_id = tbl_timing.ad_id;