聚集查询

最近更新时间: 2025-02-18 16:02:00

  • 统计记录数。
  • 复制
    复制成功
postgres=# select count(1) from tbase;
 count 
-------
     3
(1 row)
  • 统计不重复值的记录表。
  • 复制
    复制成功
postgres=# select count(distinct id) from tbase;
 count 
-------
     2
(1 row)
  • 求和。
  • 复制
    复制成功
postgres=# select sum(id) from tbase;
 sum 
-----
   4
(1 row)
  • 求最大值。
  • 复制
    复制成功
postgres=# select max(id) from tbase;
 max 
-----
   2
(1 row)
  • 求最小值。
  • 复制
    复制成功
postgres=# select min(id) from tbase;    
 min 
-----
   1
(1 row)
  • 求平均值。
  • 复制
    复制成功
postgres=# select avg(id) from tbase;       
        avg         
--------------------
 1.3333333333333333
(1 row)