当前位置:网站首页>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边栏推荐
- 抖音海外版TikTok:正与拜登政府敲定最终数据安全协议
- ros gazebo相关包的安装
- 八大排序汇总
- HOW TO CREATE AN INTERACTIVE CORRELATION MATRIX HEATMAP IN R
- map集合赋值到数据库
- C#基于当前时间,获取唯一识别号(ID)的方法
- What is the relationship between digital transformation of manufacturing industry and lean production
- deepTools对ChIP-seq数据可视化
- 电脑无缘无故黑屏,无法调节亮度。
- Cluster Analysis in R Simplified and Enhanced
猜你喜欢

Develop scalable contracts based on hardhat and openzeppelin (II)

MySQL比较运算符IN问题求解

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

6. Introduce you to LED soft film screen. LED soft film screen size | price | installation | application

The computer screen is black for no reason, and the brightness cannot be adjusted.

VS2019代码中包含中文内容导致的编译错误和打印输出乱码问题

Wechat applet uses Baidu API to achieve plant recognition

微信小程序利用百度api达成植物识别

【IDEA】使用插件一键逆向生成代码

K-Means Clustering Visualization in R: Step By Step Guide
随机推荐
Principle of scalable contract delegatecall
念念不忘,必有回响 | 悬镜诚邀您参与OpenSCA用户有奖调研
Rest (XOR) position and thinking
How to Create a Beautiful Plots in R with Summary Statistics Labels
How to Create a Nice Box and Whisker Plot in R
QT获取某个日期是第几周
亚马逊云科技 Community Builder 申请窗口开启
Mmrotate rotation target detection framework usage record
Digital transformation takes the lead to resume production and work, and online and offline full integration rebuilds business logic
ros缺少catkin_pkg
Visualization of chip SEQ data by deeptools
Always report errors when connecting to MySQL database
RPA advanced (II) uipath application practice
Resources reads 2D texture and converts it to PNG format
ROS lacks catkin_ pkg
MySQL basic statement
CTF record
flutter 问题总结
HOW TO ADD P-VALUES TO GGPLOT FACETS
excel表格中选中单元格出现十字带阴影的选中效果