如何使用having子句编写此SQL查询?

时间:2013-05-16 07:19:49

标签: sql having-clause

我的数据库架构如下

表 - X有以下3列docid(文档ID),术语(文档中的术语),count(特定docid术语出现的术语数)

docid
terms
count

如何提取以下信息 总词数总和超过300的docid数,包括重复词。

2 个答案:

答案 0 :(得分:5)

像这样: <击>

<击>
SELECT term, SUM(count) AS Totalwords
FROM tablex
GROUP BY  term
HAVING SUM(count) > 300

<击>


更新:试试这个:

SELECT docid, SUM(count)
FROM tablex
GROUP BY docid
HAVING SUM(count) > 300;

请在此处查看:

答案 1 :(得分:1)

您可以使用

SELECT docid,SUM(COUNT) AS CNT
FROM X
GROUP BY docid
HAVING SUM(count) > 300