简体   繁体   English

如何根据另一个表中的%LIKE%值过滤表

[英]How to filter a table based on %LIKE% values in another table

So i have tableA and tableB. 所以我有tableA和tableB。 A is of raw domains data, like http://www.cnn.com , where B has it trimmed up all nice and tidy, like cnn.com. A是原始域名数据,例如http://www.cnn.com ,其中B对其进行了很好的整理,例如cnn.com。 I need to pull websites that aren't in tableB that are in tableA. 我需要拉不在tableA中的tableB中的网站。 I imagine a left join with some crazy %LIKE% operator is placed in there. 我想象一个疯狂的%LIKE%运算符的左联接被放置在那里。

this is what i have so far but it doesn't work. 这是我到目前为止所拥有的,但是没有用。

SELECT tableA.domain, sum(tableA.views) views FROM `tableA` LEFT JOIN tableB ON tableA.domain %LIKE% tableB.name WHERE tableB.name IS NULL AND GROUP BY tableA.domain ORDER BY views DESC

thank you! 谢谢!

try this 尝试这个

 SELECT tableA.domain, sum(tableA.views) views FROM `tableA` 
 LEFT JOIN tableB ON tableA.domain  LIKE CONCAT('%', tableB.name ,'%')
 WHERE tableB.name IS NULL 
 GROUP BY tableA.domain 
 ORDER BY views DESC

you have two errors in your try. 您尝试时遇到两个错误。

1- LIKE CONCAT('%', tableB.name ,'%') // you have to use CONCAT 1- LIKE CONCAT('%', tableB.name ,'%') //必须使用CONCAT

2- remove the AND before group by 2-删除AND之前的group by

The % are suppose to be around the value you're comparing to, not the LIKE keyword itself. 假定%在您要比较的值附近,而不是LIKE关键字本身。

It should be something like 应该是这样的

SELECT column
FROM table
WHERE column LIKE '%pattern%';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM