我有一个MySQL表像这样出现不同的单词:指望有多少次,每行
id content
----- ------
1 Big green tree
2 Small green tree
3 Green tree
4 Small yellow tree
5 Big green lake
我想指望有多少次,每行显示不同的词。
举例:如果我要寻找的大,绿色和树。它应该返回的结果是这样的:
id count
----- ------
1 3
2 2
3 2
4 1
5 2
我想是这样的:
SELECT `content`
, COUNT(*) as count
FROM `elements`
WHERE `content` LIKE '%Big%'
OR `content` LIKE '%green%'
OR `content` LIKE '%tree%'
GROUP
BY `id`
ORDER BY count DESC;
它不工作,因为它仅返回每场比赛中的一行:
id count
----- ------
1 1
2 1
3 1
4 1
5 1
好的解决方案,但我想避免num_matches <0(不可能在where子句中添加)的行 –
看到编辑... –
正如我所说:'在哪里条款' –