MySQL-查询条件

group by
查询结果分组
[GROUP BY {col_name|position} [ASC|DESC],...]
SELECT class from tb1 GROUP BY class;

例如:统计每个班级中每种性别的学生人数,并按照班级升序排序

select class,sex,count(*) from students group by class,sex order by class;
having
分组条件
[HAVING where_condiion]
SELECT age from tb1 GROUP BY age HAVING age>10;

注:

where是对from后面指定的表进行数据筛选,属于对原始数据的筛选

having是对group by的结果进行筛选
order by
对查询结果进行排序
[ORDER BY {col_name|expr|position} [ASC|DESC],...]
limit
限制查询结果返回的数量
[LIMIT {[offset,]row_count|row_count OFFSET offset}]
例如:查询前3行

select * from students limit(0,3);

每页显示m条数据,求:显示第n页的数据

select * from students limit (n-1)*m,m;

select * from students limit 0,5;  ---每页显示5条数据,显示第一页

posted @ 2020-03-24 20:23  忆梦,惊梦  阅读(299)  评论(0编辑  收藏  举报