SQL LIKE Operator



我想做这样的事情:

SELECT *
FROM 
    dictionary t1, 
    dictionary t2
WHERE t1.category <> t2.category
    AND t1.tag <> t2.tag
    AND t1.word LIKE '% t2.word %';

如何编写SQL的'% t2.word %'部分以获得正确的结果?

 select * 
   from dictionary t1, 
        dictionary t2 -- <- Is there an intentional Cartesian Join?
  where t1.category <> t2.category and 
        t1.tag <> t2.tag and 
        t1.word like '% ' || t2.word || ' %'; -- <- check spaces!

您需要使用该列。

select * 
from dictionary t1, dictionary t2 
where t1.category<>t2.category and t1.tag<>t2.tag and t1.word like '% ' + t2.word + ' %';
select * 
from dictionary t1, dictionary t2 
where t1.category<>t2.category and t1.tag<>t2.tag and t1.word like '%'+ t2.word +'%';

这就是您想要的:

select * 
from dictionary t1, dictionary t2 
where t1.category<>t2.category and t1.tag<>t2.tag and t1.word like '% ' + t2.word + ' %';

最新更新