目前有这张表,需要能够找到包含人名的Sentences
ID FIRSTNAME LASTNAME EMAIL PHRASE
-------- --------------- ------------ --------------------------- ---------------------------------------------------------------
1 John Smith jsmith@faker.com I'm the same as other people.
2 Sarah Lane saralane23@faker.com I'm different from other people
3 Allen Borazt allenB@faker.com I guess I need another job.
4 Mike Himmy mh@faker.com We have a great time. John Smith really enjoys his time out.
5 Jillian Carters jcartrs@faker.com What happened to the car?
6 Steven Oarts SteveO2@faker.com Just chillin' over in the pool
7 Ronald Donalds don@faker.com Just in case you were wondering
8 Nancy Arist nArist@faker.com What I really want is Paul Blarts movie.
9 Paul Blart paulb@faker.com I think Nancy Arist hair color is cool.
现在我的查询看起来像这样,但它返回“未选择行”。
SELECT T.*
FROM Table T
WHERE T.Phrase Like '%' || T.FirstName || '%';
我想要的结果是这样的。
ID FIRSTNAME LASTNAME EMAIL PHRASE
-------- --------------- ------------ --------------------------- ------------------------------------------------------------------------------------------------------------------------
4 Mike Himmy mh@faker.com We have a great time. John Smith really enjoys his time out.
8 Nancy Arist nArist@faker.com What I really want is Paul Blarts movie.
9 Paul Blart paulb@faker.com I think Nancy Arist hair color is cool.
最佳答案
执行子查询并使用 exists 检查是否在短语列中找到该 fname 或 lname。
SELECT A.*
FROM Table1 A
WHERE EXISTS (
SELECT *
FROM Table1 B
WHERE B.Phrase Like '%' || A.FirstName || '%'
OR B.Phrase Like '%' || A.LastName || '%')
关于sql - Oracle SQL,在包含另一列字符串的一列中搜索字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49786161/