SQL命令讲解(二)

DQL单表查询

 

练习:

示例1: 查询购买金额最多的前10名

语句一:

select customerid,sum(totalprice)from sellsum group by customerid ORDER BY sum(totalprice) desc limit 10;

语句二:

select customerid,sum(totalprice) as total from sellsum 
group by customerid 
ORDER BY total desc limit 10;
示例2:查询联通会员以方便通知联通用户

语句一:

select customerphone customername from customer where customerphone like '130%' or customerphone like '131%' or customerphone like '186%';

语句二:

select customerphone customername from customer where substr(customerphone,1,3) in ('130','131','186')

示例3:查询2017年第四季度的商品销售数量,并按照金额倒序排序

语句:

select goodstype, sum(subtotal) as total from sell  where createtime BETWEEN  '2017-10-01 00:00:00' and '2017-12-31 23:59:59' group by  goodstype order by total desc; 

示例4: 查询商品批次和数量

语句:select batchname,quantity from goods;

结果:

 

示例5:查询进货批次和数量

语句:select batchname,count(*) from goods group by batchname;

结果:

示例6:查询每个批次进货的数量

语句:select batchname,sum(quantity) from goods GROUP BY batchname;

结果:

 示例7:查询进货数量大于500的批次

语句:

Select batchname,sum(quantity) as sum from goods group by batchname having sum >500;

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值