排序查询:
在条件查询后面 使用order by 字段名称 (默认)升序asc降序desc
通过年龄查询排序
select * from user2 order by age;
select * from user2 order by age desc;
多条件排序。逗号隔开即可
select * from user2 order by birthday desc,age asc;
有条件排序
select * from user2 like '19%' order by age desc;
聚合函数使用
sum();
获取一列总和:select sum(列属性名) from user2;
获取多列总和:select sum(age),sum(id) from urse2;
带条件:select sum(列属性名) from user2 where like 'zhang%';
null加上任何值都为null
count();
获取学生的总数,select count(*) from user2;
select count(*) from user2 where naem like '李%';
max();
select max(shuxing) form user2;
min();
select min(shuxing) form user2;
avg();
select avg(shuxing) form user2;
分组统计查询:
使用group by
统计每类商品的总金额
select product,sum(price) from user2 group by product;
having 关键字
where 的子句后面不能跟着聚合函数,如果现在使用带有聚合函数的条件穿透(分组)
总结:
select from where group by having order by