SELECT pub_id, type, MAX(price) as '最高单价', MIN(price) as '最低单价', AVG(price) as '单价平均值', COUNT(*) as '类数'
FROM titles
WHERE price > 10
GROUP by type, pub_id
HAVING AVG(price) < 20 --对聚合后的数据进行筛选过滤,而不能直接在where AVG(price) < 20
--不能直接用<>限定范围,where中不能出现函数,此时需要使用having字句
SELECT type, avg(PRICE) AS '平均单价', MAX(price), COUNT(*)
FROM titles
WHERE price > 10 and AVG(price) < 20
GROUP by type
出现错误: