很少用到MYSQL 这里有个语法问题需要大虾们帮帮忙:
UPDATE ecs_users SET `status` = 1 WHERE user_id IN( SELECT DISTINCT t1.user_id FROM ecs_users t1 LEFT JOIN ecs_user_account t2 ON t1.user_id = t2.user_id WHERE (t2.add_time IS NULL AND t1.reg_time + 180 > NOW()) OR (t2.add_time IS NOT NULL AND t2.add_time + 180 > NOW()) )
[Err] 1093 – You can”t specify target table “ecs_users” for update in FROM clause
-/* 该语句测试通过,可能返回NULL值 */ SELECT DISTINCT t1.user_id FROM ecs_users t1 LEFT JOIN ecs_user_account t2 ON t1.user_id = t2.user_id WHERE (t2.add_time IS NULL AND t1.reg_time + 180 > NOW()) OR (t2.add_time IS NOT NULL AND t2.add_time + 180 > NOW())
解决方案
40
[Err] 1093 – You can”t specify target table “ecs_users” for update in FROM clause
相似问题时建议可以先到在线翻译工具中翻译一下以理解。
MYSQL中改为如下。
update a inner join b on a.id=b.id
set a.col=b.col2
where a.name=”abc”
相似问题时建议可以先到在线翻译工具中翻译一下以理解。
MYSQL中改为如下。
update a inner join b on a.id=b.id
set a.col=b.col2
where a.name=”abc”