聚集查詢
更新時間 2025-02-14 10:21:46
最近更新時間: 2025-02-14 10:21:46
分享文章
本文介紹如何在使用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)