当前位置:网站首页>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
边栏推荐
- Seriation in R: How to Optimally Order Objects in a Data Matrice
- Liftover for genome coordinate conversion
- MTK full dump grab
- [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 a Nice Box and Whisker Plot in R
- 在连接mysql数据库的时候一直报错
- qt 仪表自定义控件
- RPA进阶(二)Uipath应用实践
- Precautions for scalable contract solution based on openzeppelin
- 抖音海外版TikTok:正与拜登政府敲定最终数据安全协议
猜你喜欢
解决uniapp列表快速滑动页面数据空白问题
Beautiful and intelligent, Haval H6 supreme+ makes Yuanxiao travel safer
Wechat applet uses Baidu API to achieve plant recognition
How to Create a Beautiful Plots in R with Summary Statistics Labels
The computer screen is black for no reason, and the brightness cannot be adjusted.
由粒子加速器产生的反中子形成的白洞
pgsql 字符串转数组关联其他表,匹配 拼接后原顺序展示
Never forget, there will be echoes | hanging mirror sincerely invites you to participate in the opensca user award research
How to Easily Create Barplots with Error Bars in R
Thesis translation: 2022_ PACDNN: A phase-aware composite deep neural network for speech enhancement
随机推荐
基于Hardhat编写合约测试用例
STM32 single chip microcomputer programming learning
Wechat applet uses Baidu API to achieve plant recognition
预言机链上链下调研
ROS lacks xacro package
C file and folder operation
2022年4月17日五心红娘团队收获双份喜报
Cluster Analysis in R Simplified and Enhanced
pgsql 字符串转数组关联其他表,匹配 拼接后原顺序展示
What is the relationship between digital transformation of manufacturing industry and lean production
Tdsql | difficult employment? Tencent cloud database micro authentication to help you
JS -- take a number randomly from the array every call, and it cannot be the same as the last time
对毕业季即将踏入职场的年轻人的一点建议
Liftover for genome coordinate conversion
时间格式化显示
qt 仪表自定义控件
Never forget, there will be echoes | hanging mirror sincerely invites you to participate in the opensca user award research
How to Create a Beautiful Plots in R with Summary Statistics Labels
Map set assignment to database
Analyse de l'industrie