题解 | #计算总和#
计算总和
https://www.nowcoder.com/practice/d8a624021183454586da94d280cc8046
两种方法(考虑sql运行顺序)
1.having:
select order_num, sum(item_price*quantity)total_price
from OrderItems
group by order_num
having sum(item_price*quantity)>=1000
order by order_num
from OrderItems
group by order_num
having sum(item_price*quantity)>=1000
order by order_num
2.子查询:
select a.order_num,a.total_price
from
from
(select order_num, sum(item_price*quantity)total_price
from OrderItems
group by order_num
order by order_num)a
where total_price>=1000
where total_price>=1000