如何确定列表是否至少具有相同的元素
产品表包含标签列:
create table product(
product char(20) primary key,
tag1 char(100),
tag2 char(100) )
标签列包含的标签被半分离的标签,例如
AB;AC;AD
RXX;AC;XAD
RP12;X455;R444;AXD
如何找到tag1和tag2列中的所有行,至少包含一个相同的标签?
例如
tag1 tag2
AB;AC;AD RXX;ZAC;XAD;AC
进行结果,因为两列都不应
两列包含AC行
tag1 tag2
AB;XAC;AD RXX;ZAC;XAD;AC
,由于所有标签都不同,因此不应将
在结果中。使用PostgreSQL 13.2
Product table contains tags columns:
create table product(
product char(20) primary key,
tag1 char(100),
tag2 char(100) )
tag columns contain tags separated by semicolon like
AB;AC;AD
RXX;AC;XAD
RP12;X455;R444;AXD
How to find all rows where tag1 and tag2 columns contain at least one same tag ?
For example row
tag1 tag2
AB;AC;AD RXX;ZAC;XAD;AC
should be in result since both columns contain AC
Row
tag1 tag2
AB;XAC;AD RXX;ZAC;XAD;AC
Should not be in result since all tags are different.
Using PostgreSQL 13.2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
&&
操作员检查列中是否有共同元素。为此,您必须首先使用String_to_array
emo in dbfiddle
You can use the
&&
operator to check if there are common elements in the columns. To do this, you must first convert the string to an array using thestring_to_array
Demo in DBfiddle