在 SQL 中增加 HAVING 子句原因是,WHERE 关键字无法与合计函数一起使用。
#查询订单总金额少于2000的客户
select name, sum(price) from tableA group by name having sun(price)>10000
#查找用户张三或者李四,订单总金额超过20000的订单总金额
select name, sum(price) from tableA where name = 'zhangsan' or name = 'lisi' group by name having sum(price) > 20000