我有一個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子句中添加)的行 –
看到編輯... –
正如我所說:'在哪裏條款' –