在update 中的 where 子句中使用子查詢:sql
UPDATE mg_page_log as a SET page_num=1 WHERE id in( SELECT id from mg_page_log WHERE id < 100 GROUP BY visit_id)
會報:code
You can't specify target table 'a' for update in FROM clause 錯誤ci
因此正確的是:get
UPDATE mg_page_log as a , ( SELECT id from mg_page_log WHERE id < 100 GROUP BY visit_id)as b SET page_num=1 WHERE a.id = b.id
——————————————————————————it
UPDATE customer as a ,customer0 as aa SET a.lastVisitTime = aa.lastFollowTime ,a.visitCount = 1 WHERE a.id = aa.id AND a.phase=2 AND a.lastVisitTime = 0