Skip to main content

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

ParameterDescription
<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 |
+------+------+------+
selectcount(*)from test_count;
+----------+
| count(*) |
+----------+
| 6 |
+----------+
selectcount(name)from test_insert;
+-------------+
| count(name) |
+-------------+
| 5 |
+-------------+
selectcount(distinct sex)from test_insert;
+---------------------+
| count(DISTINCT sex) |
+---------------------+
| 1 |
+---------------------+
selectcount(distinct id,sex)from test_insert;
+-------------------------+
| count(DISTINCT id, sex) |
+-------------------------+
| 5 |
+-------------------------+

AltStyle によって変換されたページ (->オリジナル) /