当前位置:网站首页>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边栏推荐
- Cluster Analysis in R Simplified and Enhanced
- 接口调试工具概论
- HOW TO EASILY CREATE BARPLOTS WITH ERROR BARS IN R
- How to Create a Nice Box and Whisker Plot in R
- 数字化转型挂帅复产复工,线上线下全融合重建商业逻辑
- Webauthn - official development document
- Is the stock account given by qiniu business school safe? Can I open an account?
- Programmer growth Chapter 6: how to choose a company?
- 2022年遭“挤爆”的三款透明LED显示屏
- MTK full dump grab
猜你喜欢

MySQL比较运算符IN问题求解

亚马逊云科技 Community Builder 申请窗口开启

How to Add P-Values onto Horizontal GGPLOTS

由粒子加速器产生的反中子形成的白洞

A sharp tool for exposing data inconsistencies -- a real-time verification system

Mmrotate rotation target detection framework usage record

Tidb DM alarm DM_ sync_ process_ exists_ with_ Error troubleshooting

Eight sorting summaries

数据分析 - matplotlib示例代码

GGHIGHLIGHT: EASY WAY TO HIGHLIGHT A GGPLOT IN R
随机推荐
Order by injection
MySql存储过程游标遍历结果集
Take you ten days to easily finish the finale of go micro services (distributed transactions)
动态内存(进阶四)
[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)
在连接mysql数据库的时候一直报错
CentOS8之mysql基本用法
CMake交叉编译
2022年遭“挤爆”的三款透明LED显示屏
6方面带你认识LED软膜屏 LED软膜屏尺寸|价格|安装|应用
Esp32 stores the distribution network information +led displays the distribution network status + press the key to clear the distribution network information (source code attached)
PYQT5+openCV项目实战:微循环仪图片、视频记录和人工对比软件(附源码)
BEAUTIFUL GGPLOT VENN DIAGRAM WITH R
Power Spectral Density Estimates Using FFT---MATLAB
Redis exceeds the maximum memory error oom command not allowed when used memory & gt; ' maxmemory'
mysql 基本语句
[visual studio 2019] create and import cmake project
easyExcel和lombok注解以及swagger常用注解
II Stm32f407 chip GPIO programming, register operation, library function operation and bit segment operation
C # method of obtaining a unique identification number (ID) based on the current time