问题:
SELECT * FROM tt WHERE d='20010030300002'
AND f IN
(SELECT f FROM tt WHERE d='2011062300009' AND IsAbolish=0)
因为tt在子查询中用到,所以不能这样删除。
1.用存储过程 --没试(数据量大,需要d列添加索引)
2.用临时表 --如果表数据量不大
还尝试过
SELECT @xx:=GROUP_CONCAT(CONCAT("'",f,"'"))
想使用变量,结果 在下面语句中@xx别解释成字符串
SELECT * FROM tt WHERE d='20010030300002' AND f IN(@xx)
试过直接用update也是不允许更新的。
************************
解决办法
SELECT * FROM tt WHERE d='20010030300002'
AND f IN
(select k.f from (SELECT f FROM tt WHERE d='2011062300009' AND IsAbolish=0) as t) as k)
就是将一层子查询 再套一层,
不知道根本原因是不是生成临时表
**************************explain如下 --能删除的那个语句的执行计划
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY a ALL \N \N \N \N 1828 Using where
2 DEPENDENT SUBQUERY <derived3> ALL \N \N \N \N 6 Using where
3 DERIVED b ALL \N \N \N \N 1828 Using where
***********************不能删除的语句的执行计划
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY a ALL \N \N \N \N 1828 Using where
2 DEPENDENT SUBQUERY b ALL \N \N \N \N 1828 Using where