任何人都可以帮我解决这个查询中出错的问题。
查询
update vcd_deals
set del_date='2015-09-17'
where case
when (
(select count(del_id)
from vcd_deals
where del_date=curdate()+1
and del_superSaver_deal=1)=0) then 1
else 0
end
order by del_date asc limit 3
我收到以下错误:
错误
您无法在FROM子句中为更新指定目标表'vcd_deals'。
实际上我只想更新vcd_deals
表的前三行
(select count(del_id) from vcd_deals where del_date=curdate()+1 and del_superSaver_deal=1)=0
。
请建议有没有其他方法可以做到这一点。 谢谢
答案 0 :(得分:1)
这是MySQL Parser的问题。您可以尝试使用Inner Join
。
否则,您可以将子选择括在一个单独的表中,如下所示:(未测试)
update vcd_deals
set del_date='2015-09-17'
where 0 = ( select Del_id_count
from (select count(del_id) as Del_id_count
from vcd_deals
where del_date=curdate()+1
and del_superSaver_deal=1) temp
)
order by del_date asc limit 3
答案 1 :(得分:0)
您可以按照以下方式尝试 -
UPDATE vcd_deals
SET del_date='2015-09-17'
WHERE del_date<>ADDDATE(CURDATE(), INTERVAL 1 DAY)
AND del_superSaver_deal<>1
ORDER BY del_date LIMIT 3;