day02
1、排序:order by
升序:select * from 表名 order by 字段1 asc,字段2 asc;(先按字段1排序,若字段1相同则按字段2…)
降序:select * from 表名 order by 字段1 desc,字段2 desc;
例:select * from students order by age desc,studentNo desc;
2、聚合函数 count(*),max(*),min(*),sum(*),avg(*)等
count(*):求某类字段的个数
select count(*) from students where sex='女';
max(*):求某类字段的最大值
select max(age) from students where name like '孙%';
min(*):求某类字段的最小值
sum(*):求某类字段的总和
select sum(age) from students where sex='男';
avg(*):求某类字段的平均值
select avg (age) from students where class='1班';
3、分组:group by
select 字段1,字段2,聚合函数 from 表名 group