(参考表数据)
-聚合函数-
- count函数(计数)
select count(degree) from sc;
//统计有多少同学有成绩。
- max,min函数(最大值,最小值)
select max(degree),min(degree) from sc;
//求成绩最高分和最低分。
- avg函数(平均值)
select avg(degree) from sc;
//求平均成绩。
-group by子句(分组)-
select cno from sc
group by cno;
//输出sc表中选课号类别。
-having子句(条件)-
select max(degree) from sc
group by cno
having cno='c02';
//查询课程号为“c02”的最高分。(having相当于where,但是group by函数后只能跟having)
-order by子句(排序)-
select degree from sc
group by degree desc;
//按成绩的降序排列。
select degree from sc
group by degree (asc);
//按成绩的升序排列(可省略,默认为升序)
-limit子句(偏移量)-
select degree from sc
group by degree desc
limit 2;
//取前两名成绩。
select degree from sc
group by degree desc
limit 1,2;
//取从下标为1(第2条记录)开始的两条记录。
吾独矣
终极愿望世界和平