mysql数据库简单练习(重点查询,commoditytype表!)

mysql数据库简单练习(重点查询,commoditytype表!)

1.查询所有c-type=1的商品

  • select*from commodity where c_type=1;

2.查询所有c_type=2,且进价小于100的商品

  • select*from commodity where c_type=2 and c_inprice<100;

3.查询所有c_type=3且进价小于100且售价为非空的商品

  • select*from commodity where c_type=3 and c_inprice<100 and c_outprice is not null;

4.查询所有进价大于20且小于80的商品

  • select*from commodity where c_inprice>20 and c_inprice<80;

5.查询所有进价大于等于20且小于等于80的商品

  • select*from commodity where c_inprice between 20 and 80;

6.查询所有库存为5或者10或者15的商品

  • select*from commodity where c_num in (5,10,15);

7.查询所有商品名称中带书关键字的商品

  • select*from commodity where c_name like ‘%书%’;

8.查询商品库存最大的前5件商品

  • select*from commodity order by c_num desc limit 5;

9.查询商品库存最大的第6至20件商品

  • select*from commodity order by c_num desc limit 5,15;

10.查询一共有多少库存

  • select sun(c_num) from commodity;

11.查询每种商品的平均进价

  • select c_type,avg(c_inprice) from commodity group by c_type;

12.查询每种商品的数量

  • select c_type,count(*) from commodity group by c_type;

13.将所有商品的库存数量都+10

  • update commodity set c_num=c_num+10;

14.删除没有售出价格的所有商品

  • delete from commodity where c_outprice is null;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值