首页 > 解决方案 > SQL 中的逗号分隔(带大括号)搜索

问题描述

我有一个这样的 SQL 表:

表格1:

| SomeID1        | OtherID1    | Data1
+----------------+-------------+-------------------
| abcdef-.....   | cdef123-... | {18,20,22}
| abcdef-.....   | 4554a24-... | {17,19}
| 987654-.....   | 12324a2-... | {13,19,20}

还有一张桌子:

表 2:

| SomeID2        | OtherID2    | Data2
+----------------+-------------+-------------------
| abcdef-.....   | cdef123-... | 13
| abcdef-.....   | 4554a24-... | 14
| 987654-.....   | 12324a2-... | 15
| abcdef-.....   | 4554a24-... | 16
| 987654-.....   | 12324a2-... | 17

是否可以从 table1 收集一个 Data1 值并在 table2 中搜索,例如:

select * from table2 where Data2 in ('18','20','22') 

我正在寻找这样的东西:

select * from table2 where Data2 in (select Data1 from table1 where SomeID1='abcdef') 

PD:我没有做桌子

标签: sql

解决方案


SELECT SomeID1, OtherID1, Data1 FROM Table1,Table2 WHERE SomeID1 = SomeID2 AND ....

您需要一份独一无二的参考资料


推荐阅读