欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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的某字段

相关标签: sql