sql server implements group_concat in mysql, converts columns to rows, and splices strings with delimiters

 
 
----Base
A user corresponds to multiple roles. 
Use convert(VARCHAR,role_id) to escape role_id for int type

----sql:
select b.user_id ,
  roles = stuff((select ',' + convert(VARCHAR, t.ROLE_ID) from base_user_role t where b.USER_ID = t.user_id for xml path('')) , 1 , 1 , '') from base_user_role b group by b.user_id

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325037525&siteId=291194637