代码语言:sql复制
-- 属性交换
UPDATE sys_user su1
JOIN sys_user su2 ON ( su1.nick_name = '小明' AND su2.nick_name = '小红' )
OR ( su1.nick_name = '小红' AND su2.nick_name = '小明' )
SET su1.ding_user_id = su2.ding_user_id,
su2.ding_user_id = su1.ding_user_id;
-- 查询交换后的
SELECT
*
FROM
sys_user su1
JOIN sys_user su2 ON ( su1.nick_name = '小明' AND su2.nick_name = '小红' )
OR ( su1.nick_name = '小红' AND su2.nick_name = '小明' );