更新时间:2024-12-13 GMT+08:00
分享

HAVING

HAVING

HAVING与聚合函数和GROUP BY一起使用,来控制选在哪些组。HAVING能够在分组和聚合计算之后,过滤掉不满足给定条件的组。

例如:

SELECT count(*), mktsegment, nationkey,
CAST(sum(acctbal) AS bigint) AS totalbal
FROM customer
GROUP BY mktsegment, nationkey
HAVING sum(acctbal) > 5700000
ORDER BY totalbal DESC;

相关文档