表件数count使用总结
1,常用connt形式的区别
count(1) | ||
count(*) | ||
count(列名) | 列值是NULL的时候不统计 |
2,多个表的件数统计
select * from
(select count(*) as employees_cnt from employees) employees,
(select count(*) as departments_cnt from departments) departments,
(select count(*) as salaries_cnt from salaries) salaries
3, 根据列来取得件数
select hire_date,count(*) from employees group by hire_date
4,重复去除的件数取得
SELECT COUNT(DISTINCT department_id) FROM user;
5,最快速表件数的取得
5.1 mysql
select
table_rows
from
information_schema.tables
where
table_name = 'employees'