当前位置:网站首页>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边栏推荐
- Multi line display and single line display of tqdm
- The position of the first underline selected by the vant tabs component is abnormal
- Fabric.js 3个api设置画布宽高
- How to Easily Create Barplots with Error Bars in R
- MySQL comparison operator in problem solving
- 程序员成长第六篇:如何选择公司?
- Order by注入
- ROS lacks catkin_ pkg
- 制造业数字化转型和精益生产什么关系
- Resources reads 2D texture and converts it to PNG format
猜你喜欢

Compilation errors and printout garbled problems caused by Chinese content in vs2019 code

map集合赋值到数据库

A white hole formed by antineutrons produced by particle accelerators

Redis exceeds the maximum memory error oom command not allowed when used memory & gt; ' maxmemory'

tidb-dm报警DM_sync_process_exists_with_error排查

2022年遭“挤爆”的三款透明LED显示屏

Basic usage of MySQL in centos8

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

HOW TO CREATE AN INTERACTIVE CORRELATION MATRIX HEATMAP IN R

excel表格中选中单元格出现十字带阴影的选中效果
随机推荐
How to Create a Nice Box and Whisker Plot in R
Three transparent LED displays that were "crowded" in 2022
C # method of obtaining a unique identification number (ID) based on the current time
Principle of scalable contract delegatecall
ROS lacks xacro package
Jenkins installation
Pit of the start attribute of enumrate
制造业数字化转型和精益生产什么关系
对毕业季即将踏入职场的年轻人的一点建议
JS——每次调用从数组里面随机取一个数,且不能与上一次为同一个
6. Introduce you to LED soft film screen. LED soft film screen size | price | installation | application
Tidb DM alarm DM_ sync_ process_ exists_ with_ Error troubleshooting
RPA advanced (II) uipath application practice
预言机链上链下调研
Liftover for genome coordinate conversion
Precautions for scalable contract solution based on openzeppelin
Always report errors when connecting to MySQL database
GGPlot Examples Best Reference
Multi line display and single line display of tqdm
Introduction to interface debugging tools