我有一个包含5列的表(primary_key,abstractid,sentid,wordid,term)。
此查询会提取一系列不同的术语,这些术语出现在少于6个不同的abstractid中。
SELECT
term, COUNT(distinct abstractid) AS "num"
FROM
nsfabstracts
HAVING
COUNT(distinct abstractid) < 6
GROUP BY
term
ORDER BY
"num" DESC;
如何修改上述查询以计算它返回的行数?另外,如何删除与上述查询相关联的所有行?
答案 0 :(得分:5)
懒惰,使用子选择:
SELECT count(*) FROM (
SELECT term, COUNT(distinct abstractid) AS "num" FROM nsfabstracts HAVING COUNT(distinct abstractid) < 6 GROUP BY term
)
和
DELETE FROM nsfabstracts WHERE term in (
SELECT term, COUNT(distinct abstractid) AS "num" FROM nsfabstracts HAVING COUNT(distinct abstractid) < 6 GROUP BY term
)