聚集查询
更新时间 2025-02-14 10:21:42
最近更新时间: 2025-02-14 10:21:42
本文介绍如何在使用SELECT语法时进行聚集查询,例如统计记录数、不重复值的记录表,以及求和等。
统计记录数。
teledb=# select count(1) from teledb_pg; count ------- 5 (1 row)
统计不重复值的记录表。
teledb=# select count(distinct id) from teledb_pg; count ------- 4 (1 row)
求和。
teledb=# select sum(id) from teledb_pg; sum ----- 11 (1 row)
求最大值。
teledb=# select max(id) from teledb_pg; max ----- 4 (1 row)
求最小值。
teledb=# select min(id) from teledb_pg; min ----- 1 (1 row)
求平均值。
teledb=# select avg(id) from teledb_pg; avg -------------------- 2.2000000000000000 (1 row)