COUNT
Descriptionβ
Returns the number of non-NULL records in the specified column, or the total number of records.
Syntaxβ
COUNT(DISTINCT <expr> [,<expr>,...])
COUNT(*)
COUNT(<expr>)
Parametersβ
Parameter | Description |
---|---|
<expr> | Conditional expression (column name) |
Return Valueβ
The return value is of numeric type. If expr is NULL, there will be no parameter statistics.
Exampleβ
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 |
+-------------------------+