当前位置:网站首页>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 overseas tiktok: finalizing the final data security agreement with Biden government
- 解决uniapp列表快速滑动页面数据空白问题
- PX4 Position_ Control RC_ Remoter import
- The difference between SQL left join main table restrictions written after on and where
- Never forget, there will be echoes | hanging mirror sincerely invites you to participate in the opensca user award research
- GGHIGHLIGHT: EASY WAY TO HIGHLIGHT A GGPLOT IN R
- Precautions for scalable contract solution based on openzeppelin
- How to Visualize Missing Data in R using a Heatmap
- 通过券商经理的开户二维码开股票账户安全吗?还是去证券公司开户安全?
- ASTParser 解析含有emum 枚举方法的类文件的踩坑记
猜你喜欢

2022年4月17日五心红娘团队收获双份喜报

电脑无缘无故黑屏,无法调节亮度。

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

R HISTOGRAM EXAMPLE QUICK REFERENCE

【云原生】2.5 Kubernetes 核心实战(下)

How to Add P-Values onto Horizontal GGPLOTS

HOW TO EASILY CREATE BARPLOTS WITH ERROR BARS IN R

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

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

PowerBI中导出数据方法汇总
随机推荐
HOW TO EASILY CREATE BARPLOTS WITH ERROR BARS IN R
基于 Openzeppelin 的可升级合约解决方案的注意事项
抖音海外版TikTok:正与拜登政府敲定最终数据安全协议
webauthn——官方开发文档
Gaode draws lines according to the track
CentOS8之mysql基本用法
SQLite modify column type
程序员成长第六篇:如何选择公司?
Amazon cloud technology community builder application window opens
HOW TO CREATE A BEAUTIFUL INTERACTIVE HEATMAP IN R
ASTParser 解析含有emum 枚举方法的类文件的踩坑记
VS2019代码中包含中文内容导致的编译错误和打印输出乱码问题
spritejs
Programmer growth Chapter 6: how to choose a company?
Installation of ROS gazebo related packages
C # method of obtaining a unique identification number (ID) based on the current time
Seriation in R: How to Optimally Order Objects in a Data Matrice
Jenkins installation
Esp32 audio frame esp-adf add key peripheral process code tracking
Tiktok overseas tiktok: finalizing the final data security agreement with Biden government