Oracle select mutual sub string

喜你入骨 提交于 2021-02-08 11:19:29

问题


I would like to return new table in ORACLE where all rows that have same the values in 'col' columns group together and the 'description' column will contain only the mutual sub strings when the different characters will replaced by '...'

how can I do that? May i get your help please?

Basic code to start with: SELECT col,description FROM table group by col;

Example 1:

col description
1   Today is 
1   Today is a good day
1   Today is perfect day
2   Hello world
2   Hello

results:

col description
1   Today is …
2   Hello…

Example 2:

col description
1   Today is a good day
1   Today is perfect day
2   Hello world
2   Hello I'm here
3   Hi

results:

col description
1   Today is …
2   Hello…
3   Hi

thanks!


回答1:


This answers the original version of the question.

You can use not exists:

select col, description || ' ...'
from t
where not exists (select 1
                  from t t2
                  where t2.description like t.description || '%' and
                        t2.descriptoin <> t.description
                 );

Note that on a large table, this will not be efficient!



来源:https://stackoverflow.com/questions/62754557/oracle-select-mutual-sub-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!