sec)
2.6.7 数据统计
使用COUNT()函数计算表中的数据数目(比如emp表中的员工数目) mysql> select count(*) from emp;
查询结果如下: +----------+ | count(*) | +----------+ | 3 | +----------+ 1 row in set (0.01 sec)
统计工资上5000的数目 mysql> select count(*) from emp where emp_sal>5000;
查询结果如下: +----------+ | count(*) | +----------+ | 2 | +----------+ 1 row in set (0.00 sec)
统计男女职工数目:(GROUP BY语句分类) mysql> select emp_sex,count(*) from emp group by emp_sex;
查询结果如下: +---------+----------+ | emp_sex | count(*) | +---------+----------+ | fmale | 1 | | male | 2 | +---------+----------+ 2 rows in set (0.01 sec)
使用数据统计函数(MIN(),MAX(),SUM(),AVG()) mysql> select -> min(emp_sal) as min_salary, -> max(emp_sal) as max_salary, -> sum(emp_sal) as sum_salary, -> avg(emp_sal) as avg_salary, -> count(*) as employee_num -> from emp;
查询结果如下: +------------+------------+------------+------------+--------------+ | min_salary | max_salary | sum_salary | avg_salary | employee_num | +------------+------------+--------- |