创建分组
select vend_id, count(*) as num_prods
from products
group by vend_id;
过滤分组:过滤两个以上订单的分组
select cust_id, count(*) as orders
from orders
group by cust_id
having count(*) >= 2;
过滤具有2个(含)以上产品、价格为10(含)以上的供应商
select vend_id, count(*) as num_prods
from products
where prod_price >= 10
group by vend_id
having count(*)>= 2;
分组和排序:检索总计订单价格大于等于50的订单的订单号和总计订单价格,按总计订单价格排序输出
select order_num, sum(quantity*item_price) as ordertotal
from orderitems
group by order_num
having sum(quantity*item_price) >=50
order by ordertotal;
2951

被折叠的 条评论
为什么被折叠?



