问题
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