Returns the number of non-NULL records in the specified column, or the total number of records.
COUNT(DISTINCT <expr> [,<expr>,...]) COUNT(*) COUNT(<expr>)
| Parameter | Description |
|---|---|
<expr> | Conditional expression (column name) |
The return value is of numeric type. If expr is NULL, there will be no parameter statistics.
select * from test_count;
+------+------+------+ | id | name | sex | +------+------+------+ | 1 | 1 | 1 | | 2 | 2 | 1 | | 3 | 3 | 1 | | 4 | 0 | 1 | | 4 | 4 | 1 | | 5 | NULL | 1 | +------+------+------+
select count(*) from test_count;
+----------+ | count(*) | +----------+ | 6 | +----------+
select count(name) from test_insert;
+-------------+ | count(name) | +-------------+ | 5 | +-------------+
select count(distinct sex) from test_insert;
+---------------------+ | count(DISTINCT sex) | +---------------------+ | 1 | +---------------------+
select count(distinct id,sex) from test_insert;
+-------------------------+ | count(DISTINCT id, sex) | +-------------------------+ | 5 | +-------------------------+