当前位置:网站首页>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边栏推荐
- 由粒子加速器产生的反中子形成的白洞
- C#多维数组的属性获取方法及操作注意
- 原生方法合并word
- Is the Ren domain name valuable? Is it worth investing? What is the application scope of Ren domain name?
- 基于 Openzeppelin 的可升级合约解决方案的注意事项
- deepTools对ChIP-seq数据可视化
- How to Easily Create Barplots with Error Bars in R
- 揭露数据不一致的利器 —— 实时核对系统
- The difference between SQL left join main table restrictions written after on and where
- Jinshanyun - 2023 Summer Internship
猜你喜欢

C#多维数组的属性获取方法及操作注意

念念不忘,必有回响 | 悬镜诚邀您参与OpenSCA用户有奖调研

Is the Ren domain name valuable? Is it worth investing? What is the application scope of Ren domain name?

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

A white hole formed by antineutrons produced by particle accelerators

Power Spectral Density Estimates Using FFT---MATLAB

GGPLOT: HOW TO DISPLAY THE LAST VALUE OF EACH LINE AS LABEL

PowerBI中导出数据方法汇总

Multi line display and single line display of tqdm

ImportError: cannot import name ‘Digraph‘ from ‘graphviz‘
随机推荐
Gaode draws lines according to the track
CentOS8之mysql基本用法
Compilation errors and printout garbled problems caused by Chinese content in vs2019 code
The position of the first underline selected by the vant tabs component is abnormal
电脑无缘无故黑屏,无法调节亮度。
What is the relationship between digital transformation of manufacturing industry and lean production
ros缺少catkin_pkg
Rest (XOR) position and thinking
From the perspective of attack surface, see the practice of zero trust scheme of Xinchuang
PYQT5+openCV项目实战:微循环仪图片、视频记录和人工对比软件(附源码)
Always report errors when connecting to MySQL database
MTK full dump grab
Redis超出最大内存错误OOM command not allowed when used memory > 'maxmemory'
TDSQL|就业难?腾讯云数据库微认证来帮你
PHP query distance according to longitude and latitude
JS -- take a number randomly from the array every call, and it cannot be the same as the last time
HOW TO ADD P-VALUES TO GGPLOT FACETS
Homer预测motif
How to Easily Create Barplots with Error Bars in R
ESP32存储配网信息+LED显示配网状态+按键清除配网信息(附源码)