篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql HAVING - 过滤组相关的知识,希望对你有一定的参考价值。
\!h NOTE - HAVING always comes after GROUP BY but before ORDER BY and LIMIT.
\!h WHERE vs HAVING
-- Limit results of a query based on values of individual rows = WHERE.
-- Limit results of a query bason on an aggregate property(like count()) = HAVING.
\!h Example - Average downloads for each price point:
SELECT price,
ROUND(AVG(downloads))
FROM fake_apps
GROUP BY price;
-- some price points don't have many apps, so the average is less meaningful
-- restrict prices so the total number of apps at that price point is higher than 9:
SELECT price,
ROUND(AVG(downloads))
FROM fake_apps
GROUP BY 1
HAVING COUNT(*) > 9;