SelectDB Enterprise
参考手册
SQL 函数
聚合函数
COUNT

COUNT

描述

返回指定列的非 NULL 记录数,或者记录总数

语法

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

参数

参数说明
<expr>条件表达式(列名)

返回值

返回值为数值类型。如果 expr 为 NULL,则不参数统计

举例

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 |
+-------------------------+
© 2025 北京飞轮数据科技有限公司 京ICP备2022004029号 | Apache、Apache Doris 以及相关开源项目名称均为 Apache 基金会商标