0
点赞
收藏
分享

微信扫一扫

【练习】8. 基本查询DQL-排序和聚合查询

NicoalsNC 2022-01-30 阅读 73
sql
-- 排序查询
-- 1.使用价格降序排序
select * from product order by price desc;
-- 2.在价格降序的基础上,以分类排序(即价格相同时以分类排序)
select * from product order by price desc, category_id desc;
-- 3.显示商品的价格(去重),并降序排序
select distinct price from product order by price desc;

-- 聚合查询
-- 1.查询商品总条数
select count(pid) from product;
-- 2.查询价格大于200的商品总条数
select count(pid) from product where price > 200;
-- 3.查询分类为c001的所有商品总价
select sum(price) from product where category_id = 'c001';
-- 4.查询商品的最大价格
select max(price) as max_price from product;
-- 5.查询商品的最小价格
select min(price) as min_price from product;
-- 3.查询分类为c003的商品平均价格
select avg(price) as avg_price from product where category_id = 'c002';
举报

相关推荐

0 条评论