比较两列,必须使用SQL提取不在A列中的单词



我正在尝试比较两列,例如

select * from table1
Column_1                column_2
----------------        ------------------
Swetha                  Swetha is working in Chennai
Raju                    Raju is studying 10 std
ranjith                 Rantith played yesterday
how to play             how to play Cricket
My name is              my name is john

我的输出是

Column_1                column_2                         column_3
----------------        ------------------               ------------------------
Swetha                  Swetha is working in Chennai     is working in Chennai
Raju                    Raju is studying 10 std          is studying 10 std
ranjith                 Rantith played yesterday         played yesterday
how to play             how to play Cricket              Cricket
My name is              my name is john                  john

如果一个单词出现在中间,它也应该像下面的一样删除

Column_1                column_2
----------------        ------------------
Swetha working          Swetha is working in Chennai
Raju 10th               Raju is studying 10th std

输出:

Column_1                column_2                         column_3
----------------        ------------------               ------------------------
Swetha working          Swetha is working in Chennai     is in Chennai
Raju 10th               Raju is studying 10th std        is studying std

您似乎想要replace():

select t.*, replace(column_2, column_1, '') column_3 from table1 t

最新更新