当前位置:网站首页>PgSQL string is converted to array and associated with other tables, which are displayed in the original order after matching and splicing
PgSQL string is converted to array and associated with other tables, which are displayed in the original order after matching and splicing
2022-07-02 11:48:00 【wyazyf】
Realization principle :
1.unnest(string_to_array(mnc.email_user_id , ',')) String to array Turn into a row and then match
2.WITH ORDINALITY a(user_id, nr) This function is used to display subscripts , Easy to sort later
3. After matching, aggregate in the original order
The source data is shown in the red box below

The effect you want to achieve is as follows ( In the same order )

Realized sql as follows
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边栏推荐
- vant tabs组件选中第一个下划线位置异常
- The position of the first underline selected by the vant tabs component is abnormal
- ESP32存储配网信息+LED显示配网状态+按键清除配网信息(附源码)
- CentOS8之mysql基本用法
- PLC-Recorder快速监控多个PLC位的技巧
- Principe du contrat évolutif - delegatecall
- TDSQL|就业难?腾讯云数据库微认证来帮你
- R HISTOGRAM EXAMPLE QUICK REFERENCE
- Wechat applet uses Baidu API to achieve plant recognition
- easyExcel和lombok注解以及swagger常用注解
猜你喜欢

【2022 ACTF-wp】

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

Cluster Analysis in R Simplified and Enhanced

Always report errors when connecting to MySQL database

MySQL comparison operator in problem solving

动态内存(进阶四)

A white hole formed by antineutrons produced by particle accelerators

map集合赋值到数据库
![[visual studio 2019] create MFC desktop program (install MFC development components | create MFC application | edit MFC application window | add click event for button | Modify button text | open appl](/img/6a/111da81436659c7502648907ec1367.jpg)
[visual studio 2019] create MFC desktop program (install MFC development components | create MFC application | edit MFC application window | add click event for button | Modify button text | open appl

How to Create a Nice Box and Whisker Plot in R
随机推荐
How to Create a Nice Box and Whisker Plot in R
easyExcel和lombok注解以及swagger常用注解
The position of the first underline selected by the vant tabs component is abnormal
电脑无缘无故黑屏,无法调节亮度。
Eight sorting summaries
Programmer growth Chapter 6: how to choose a company?
Mmrotate rotation target detection framework usage record
2022年遭“挤爆”的三款透明LED显示屏
时间格式化显示
ASTParser 解析含有emum 枚举方法的类文件的踩坑记
PYQT5+openCV项目实战:微循环仪图片、视频记录和人工对比软件(附源码)
SSRF
Jenkins installation
八大排序汇总
Is the Ren domain name valuable? Is it worth investing? What is the application scope of Ren domain name?
R HISTOGRAM EXAMPLE QUICK REFERENCE
可昇級合約的原理-DelegateCall
解决uniapp列表快速滑动页面数据空白问题
JS -- take a number randomly from the array every call, and it cannot be the same as the last time
Is it safe to open a stock account online? I'm a novice, please guide me