メインコンテンツまでスキップ
バージョン: 4.x

COUNT

デスクリプション

指定されたカラム内のNULL以外のレコード数、または総レコード数を返します。

Syntax

COUNT(DISTINCT <expr> [,<expr>,...])
COUNT(*)
COUNT(<expr>)

パラメータ

Parameterデスクリプション
<expr>条件式(カラム名)

Return Value

戻り値は数値型です。exprがNULLの場合、パラメータ統計は存在しません。

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 |
+-------------------------+