postgresql 合并函数 string_agg

pgsql数据库语法

SELECT a.id,a.name as "companyName",a.xydm,a.fddbr,string_agg(
case
when d.zzlx = 1 then '路基路面'
when d.zzlx = 2 then '桥梁'
when d.zzlx = 3 then '隧道'
when d.zzlx = 4 then '交通安全设施' end
||
case
when d.zzdj = 1 then '甲级'
when d.zzdj = 2 then '乙级'
else '' end , ',') as zz
from company_info a
left join company_info_snapshot b on a.id = b.company_id
left join company_aptitude_r c on c.snapshot_id = b.id
left join aptitude d on c.aptitude_id = d.id
where d.id is not null and a.del_flag = 2 and d.del_flag = 2 and b.del_flag = 2 and zt = 2
and concat(a.name,a.xydm) like concat('%','','%')
and d.zzlx = 1
GROUP BY a.id,a.xydm,a.fddbr

=====================================================

MySQL数据库语法

select group_concat(role_id) as roleName,user_id from sys_user_role group by user_id

 

posted @ 2022-07-20 16:24  懂得归零  阅读(495)  评论(0编辑  收藏  举报