postgresql - 使用 string_agg 更新 Postgresql
问题描述
我有两张表,分别是表 1 和表 2。我需要将两张表与派对 ID 匹配。如果当事人 id 匹配并且域也匹配,则无需更新无效电子邮件列中的任何内容。如果当事方 id 匹配并且域与表 1 不匹配,则在无效列中使用逗号分隔更新所有域
任何人都可以帮我解决这个问题......!
解决方案
你可以试试这个:
update table2
set invalid_email=array_to_string(t1.domaines,';')
from (select party_id,array_agg(domaine) as domaines from table1 group by party_id) t1
where table2.party_id=t1.party_id and table2.domaine not in (select unnest(domaines))
推荐阅读
- oracle - 甲骨文-Java | 在 30 分钟到 1 小时内更新 6000 行| 非主非索引复合键
- python - python字典的原始字符串(?)
- git - DOCKER 中的“致命:无法自动检测电子邮件地址”
- azure - 非静态天蓝色函数崩溃
- regex - 正则表达式“”到“”有条件
- node.js - 如何在 Heroku for node.js 项目上安装和支持 SAP NW RFC SDK
- firebase-realtime-database - 如何使用 Firebae 实时数据库日期发送自动推送通知?
- java - 如何发现 Spring Cloud Eureka Client 内存泄漏原因?
- sql-server - 多对多关系模式
- c++ - 尝试创建和定义类的静态成员时出错