你知道我如何将结果与下列任务分离开来吗。。
我有一个列,它对应以下值:

col_1
10001A
10001A10002A
10001A10002A10003A
10004A
10004A10005B
10006A
10007A
10007A10008A

我应该只选择没有子代的行-
col_1
10001A10002A10003A
10004A10005B
10006A
10007A10008A

最佳答案

您需要一个类似的条件来查找这些行:

select *
from the_table t1
where not exists (select *
                  from the_table t2
                  where t2.col_1 like t1.col_1||'%'
                   and t1.col_1 <> t2.col_2);

在线示例:https://rextester.com/GVGVV77242

关于sql - 如何将结果与父字符串隔离?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56614829/

10-13 02:51