查询
selelct
where
group by
having
order by
limit
--having 前面必须得有group by
--order by 按照字段名或者统计结果排序
分组函数
sum,count,avg,max ,min
#select sum(salary) as '总工资' from employee
#select count(id) from employee --如果count(字段名),那么会排除该字段是NULL的值
#select count(1) from employee
#select count(*) from employee
#select sum(salary) from employee where month=1
分组统计
#select month,avg(salary) from employee group by month
where和having的区别
(1)where后面是不允许使用分组函数,having后面可以加分组函数
(2)where是用于"原表"中记录的筛选,having是用于统计结果的筛选
#select month,avg(salary) from employee group by month having avg(salary)>1500
#select month,avg(salary) as agv_salary from employee group by month having agv_salary>1500
posted on 2020-06-19 15:28 happygril3 阅读(154) 评论(0) 收藏 举报
浙公网安备 33010602011771号