MySQL的计数大于2
我有以下表结构
+ id + word + +------+--------+
表中充满了给定文本的低级单词,所以文本
你好,再见
会导致
+ id + word + +------+--------+ + 1 + hello + +------+--------+ + 2 + bye + +------+--------+ + 3 + hello + +------+--------+
我想做一个SELECT查询,将返回表中至less两次重复的单词数(如hello)
SELECT COUNT(id) FROM words WHERE (SELECT COUNT(words.word))>1
当桌子很大的时候,这当然是错误的,超负荷的。 任何想法如何达到这样的目的? 在上面给出的例子中,我期望1
要获取多次出现的单词列表以及出现频率,请使用GROUP BY和HAVING的组合:
SELECT word, COUNT(*) AS cnt FROM words GROUP BY word HAVING cnt > 1
要查找上述结果集中的单词数,请将其用作子查询,并对外部查询中的行进行计数:
SELECT COUNT(*) FROM ( SELECT NULL FROM words GROUP BY word HAVING COUNT(*) > 1 ) T1
SELECT count(word) as count FROM words GROUP BY word HAVING count >= 2;
SELECT word, COUNT(*) FROM words GROUP by word HAVING COUNT(*) > 1