mysql-in关键字,分组查询,分页查询
1. in关键字,组查询
# 使用or来查询的化,不方便而且参数一多比较傻
select * from users where id=1 or id=2 or id=4;
select * from users where id in(1,2,4)
select * from users where id not in (2,3) order by javascore ase;
2. 分组查询 group by
如果一个查询语句使用了group by,则后面的条件要使用having关键字
CREATE TABLE godds(
id BIGINT(20) NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT '主键',
goodName VARCHAR(40) COMMENT '商品名称',
goodCategory VARCHAR(20) COMMENT '商品种类'
)
RENAME TABLE godds TO goods
select * from goods group by goodCate having goodCate
3. 分页查询 limit
#goods表中有7条数据记录,每页显示3条,总共可以分3页
#获取第一页数据
SELECT * FROM goods LIMIT 0,3;
#获取第二页数据
SELECT *FROM goods LIMIT 3,3;
#获取第三页的数据
SELECT * FROM goods LIMIT 6,3;
SELECT * FROM goods LIMIT (pageNo-1)*pageSize,pageSize;