You can't specify target table '##' for update in FROM clause

错误sql :

update tb_lts_intent_pattern set del_status = 0 where id in 
(select id from tb_lts_intent_pattern where  del_status = 1 and intent_id not in 
(select id from tb_lts_intent where del_status = 1) )

报错信息:

You can't specify target table 'tb_lts_intent_pattern' for update in FROM clause

错误原因:

MySQL中,不能先select出同一表中的某些值,再update这个表(在同一语句中)。

正确sql :

update tb_lts_intent_pattern set del_status = 0 where id in 
(select a.id from (select id from tb_lts_intent_pattern where  
   del_status = 1 and intent_id not in 
( SELECT id from tb_lts_intent where del_status = 1 )) a)

迄今为止写的最牛逼的sql

update tb_lts_dict set value = 0.3 * (2 / PI() * ATAN(log(2, freq + 2))) + 0.7 * ((freq-(select a.min from (select MIN(freq) as min from tb_lts_dict where nature = '电影名') a) + 1)/ ((select b.max from (select MAX(freq) as max from tb_lts_dict where nature = '电影名') b) - (select c.min from (select MIN(freq) as min from tb_lts_dict where nature = '电影名') c) + 1 )) where nature = "电影名"

你可能感兴趣的:(You can't specify target table '##' for update in FROM clause)