mysql分页分组查询_mysql(7)分组查询和分页查询

同时查询多条数据:

select * from students where id =1 or id=2 or id=3;

select * from students where id in (1,2,3);

select * from students where id not in(2,3);

同时查询数据+ 排序:

select * from students where id in (2,3) order by python_grade ASC;

分组查询: group by :

create table goods( id bigint(20) not null auto_increment primary key , goodName varchar(40) , goodCategory varchar(20) );

insert into goods (goodName, goodCategory ) values('apple','phone') ,('oppo' ,'phone' ),('mac' ,'computer' ),('lenovo' ,'computer'),('vivo','phone');

查询goods商品的种类:

select goodCategory from goods group by goodCategory;

查询goods商品是否存在类型

gruop by +having

f134cff3328917ac58b8d7236f64b5e0.png

select goodCategory from goods group by goodCategory having goodCategory='phone';

分页:(limit 起始下标,每页显示数据量)

goods 表中有7条数据,每页显示3条,一共可以显示3页;

获取第一页数据: select * from goods limit 0,3;

获取第二页数据: select * from goods limit 3,3;

获取第三页数据:select * from goos limit 6,3;

select * from goods limit (pageNumber-1)*pageSize,pageSize;

799e641c7bd743f62e4253d0439622e9.png

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值