当前位置:网站首页>pgsql 字符串转数组关联其他表,匹配 拼接后原顺序展示
pgsql 字符串转数组关联其他表,匹配 拼接后原顺序展示
2022-07-02 09:41:00 【wyazyf】
实现原理:
1.unnest(string_to_array(mnc.email_user_id , ','))字符串转数组 在转成行然后进行匹配
2.WITH ORDINALITY a(user_id, nr)此函数用于显示下标,便于后边排序
3.匹配后按原顺序聚合即可
源数据如下图红框中

想要实现的效果如下(顺序一致)

实现的sql如下
select
string_agg(b.user_name || '(' || b.user_id || ')', ',')as emailUserName ,
b.email_user_id
from
(
select
su.user_name,
su.user_id ,
mnc.*
from
fas_mail_notification_config mnc,
unnest(string_to_array(mnc.email_user_id , ','))with ordinality a(user_id,nr)
left join sec_user su on a.user_id = su.user_id
where
mnc.delete_flg = 0
and mnc.bg_id = '49bd50924c434556aca0193bcffb2dce'
and mnc.business_type = '1'
order by
mnc.id,
mnc.bg_id ,
a.nr
)b
group by
b.id,
b.bg_id,
b.email_user_id边栏推荐
- [idea] use the plug-in to reverse generate code with one click
- A white hole formed by antineutrons produced by particle accelerators
- ImportError: cannot import name ‘Digraph‘ from ‘graphviz‘
- 在网上开股票账户安全吗?我是新手,还请指导
- ImportError: cannot import name ‘Digraph‘ from ‘graphviz‘
- Importerror: impossible d'importer le nom « graph» de « graphviz»
- Functional interfaces and method references
- Visualization of chip SEQ data by deeptools
- Amazon cloud technology community builder application window opens
- Homer forecast motif
猜你喜欢

预言机链上链下调研

2022年4月17日五心红娘团队收获双份喜报

Principle of scalable contract delegatecall

TDSQL|就业难?腾讯云数据库微认证来帮你

RPA进阶(二)Uipath应用实践

由粒子加速器产生的反中子形成的白洞

数字化转型挂帅复产复工,线上线下全融合重建商业逻辑

Tdsql | difficult employment? Tencent cloud database micro authentication to help you

ImportError: cannot import name ‘Digraph‘ from ‘graphviz‘

Mmrotate rotation target detection framework usage record
随机推荐
MySQL comparison operator in problem solving
How to Create a Beautiful Plots in R with Summary Statistics Labels
LVM operation
亚马逊云科技 Community Builder 申请窗口开启
Redis exceeds the maximum memory error oom command not allowed when used memory & gt; ' maxmemory'
SSRF
6. Introduce you to LED soft film screen. LED soft film screen size | price | installation | application
Introduction to interface debugging tools
On April 17, 2022, the five heart matchmaker team received double good news
Attribute acquisition method and operation notes of C # multidimensional array
Visualization of chip SEQ data by deeptools
Multi line display and single line display of tqdm
How to Create a Nice Box and Whisker Plot in R
The difference between SQL left join main table restrictions written after on and where
Seriation in R: How to Optimally Order Objects in a Data Matrice
CentOS8之mysql基本用法
微信小程序利用百度api达成植物识别
Mmrotate rotation target detection framework usage record
MTK full dump grab
Supermarket (heap overload