无法显示在表格中的单词总数

时间:2014-10-13 02:25:46

标签: sql

我在查找单词出现在整个表格中的总次数时遇到了麻烦。 我的代码目前只计算单词出现在每一行中的次数。我该如何解决这个问题?

SELECT comments, COUNT(*) AS total FROM AE
WHERE comments like '%'%' 
GROUP BY comments

如果您想要更多代码,请询问:)

2 个答案:

答案 0 :(得分:0)

你可以获得COUNT

SELECT  COUNT(*) AS total FROM AE
WHERE comments like '%abcd%' 

您只需使用WHERE

即可获得与该字词匹配的所有评论
SELECT  comments AS total FROM AE
WHERE comments like '%abcd%' 

如果您希望COUNT重复评论,则可以使用“CROSS APPLY”

select * from (SELECT  comments  
FROM AE
WHERE comments like '%abcd%' ) T
CROSS APPLY 
  ( SELECT  COUNT(*) AS total FROM AE
WHERE comments like '%abcd%' ) T2

答案 1 :(得分:0)

这个数字是否足够?

SELECT COUNT(comments) AS total FROM AE
WHERE comments like '%'%'