当前位置:网站首页>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边栏推荐
- Tdsql | difficult employment? Tencent cloud database micro authentication to help you
- PLC-Recorder快速监控多个PLC位的技巧
- [multithreading] the main thread waits for the sub thread to finish executing, and records the way to execute and obtain the execution result (with annotated code and no pit)
- HOW TO CREATE AN INTERACTIVE CORRELATION MATRIX HEATMAP IN R
- HOW TO CREATE A BEAUTIFUL INTERACTIVE HEATMAP IN R
- GGPlot Examples Best Reference
- 基于Hardhat编写合约测试用例
- deepTools对ChIP-seq数据可视化
- 基于Hardhat和Openzeppelin开发可升级合约(一)
- How to Easily Create Barplots with Error Bars in R
猜你喜欢

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

Tiktok overseas tiktok: finalizing the final data security agreement with Biden government

预言机链上链下调研

CentOS8之mysql基本用法

Wechat applet uses Baidu API to achieve plant recognition

Three transparent LED displays that were "crowded" in 2022

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

HOW TO CREATE A BEAUTIFUL INTERACTIVE HEATMAP IN R

制造业数字化转型和精益生产什么关系

Digital transformation takes the lead to resume production and work, and online and offline full integration rebuilds business logic
随机推荐
电脑无缘无故黑屏,无法调节亮度。
The difference between SQL left join main table restrictions written after on and where
Skills of PLC recorder in quickly monitoring multiple PLC bits
Importerror: impossible d'importer le nom « graph» de « graphviz»
Map set assignment to database
bedtools使用教程
C file and folder operation
How to Create a Nice Box and Whisker Plot in R
Principe du contrat évolutif - delegatecall
Tidb DM alarm DM_ sync_ process_ exists_ with_ Error troubleshooting
Is the stock account given by qiniu business school safe? Can I open an account?
抖音海外版TikTok:正与拜登政府敲定最终数据安全协议
PX4 Position_Control RC_Remoter引入
What week is a date obtained by QT
ESP32存储配网信息+LED显示配网状态+按键清除配网信息(附源码)
Native method merge word
GGPLOT: HOW TO DISPLAY THE LAST VALUE OF EACH LINE AS LABEL
MySQL linked list data storage query sorting problem
TDSQL|就业难?腾讯云数据库微认证来帮你
对毕业季即将踏入职场的年轻人的一点建议