任何人都可以使用此查询来帮助我查询中出现什么问题。在mysql中使用select和case语句进行更新
查询
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
我收到以下错误:
错误
You can't specify target table 'vcd_deals' for update in FROM clause.
其实我想更新vcd_deals
表的前三行 (select count(del_id) from vcd_deals where del_date=curdate()+1 and del_superSaver_deal=1)=0
只有当。
请建议是否有任何其他方式来做到这一点。 感谢
它的工作感谢兄弟,我有一个问题,你为什么使用两个次选择查找'Del_id_count' – Aabid
这是派生表,它有助于提高性能。查看链接[Link1](http://www.databasejournal.com/features/mysql/article.php/3914401/Use-Derived-Tables-in-Your-MySQL-Queries-to-Improve-Database-Performance。 htm),[Link2](http://forums.devshed.com/mysql-help-4/subquery-vs-derived-table-944181.html)以获取更多详细信息 – Crazy2crack
Hello @ Crazy2crack您可以在另一个查询中帮助我吗? 。我想用这个查询更新两个表列。 – Aabid