mysql的update复杂语句
程序员文章站
2022-06-01 16:31:41
...
UPDATE t_s_user a ,(SELECT ur.id,bu.username,bu.realname,ur.roleids,
(SELECT r.rolename FROM t_s_role r WHERE r.id IN(IFNULL(ur.roleids,''))) rolenames
from t_s_base_user bu LEFT JOIN (
SELECT u.id,ru.roleids
FROM t_s_user u LEFT join (
SELECT userid,GROUP_CONCAT(roleid) roleids FROM t_s_role_user GROUP BY userid ) ru on ru.userid = u.id
) ur ON ur.id = bu.ID where ur.id not in (
SELECT userid FROM t_s_role_user GROUP BY userid HAVING COUNT(roleid)>1)) b SET a.business_rank_personnel_id
= b.roleids WHERE a.id = b.id
update两个表,格式如下:
update 表a,表b(表b是子查询虚拟的表) set 表a的某字段= 表b的某字段
where 表a的某字段= 表b的某字段
上一篇: GitBook使用
下一篇: Navicat连不上本地mysql8