我正在尝试更新条件为的user_status
文件
update pm_users
set user_status = if (
(select u.user_status from pm_users u where u.user_id = 3
) = '1', '0', '1' )
where user_id = 3
意味着如果CCD_ 2则用0更新状态,并且如果用户状态是0则用1更新状态。
我收到错误:You can't specify target table 'pm_users' for update in FROM clause
我想这意味着我不能像上面那样对同一个表使用这个查询?我不确定
请帮我走正确的路,让我改正。
尝试以下
update pm_users
set user_status = case when user_status = 0 then 1 else 0 end
where user_id = 3
不如试试CASE
update pm_users
set user_status = CASE WHEN user_status = '1' THEN '0' ELSE '1' END
WHERE user_id = 3