Skip to content

Counting and averaging · ⁨计数与求平均⁩

English

Summarising with aggregate functions

Sometimes you do not want the rows themselves, but a summary of them. Aggregate functions turn many rows into a single value:

  • COUNT(*) — how many rows
  • SUM(col) — the total
  • AVG(col) — the average
  • MIN(col) / MAX(col) — the smallest / largest

中文

用聚合函数做汇总

有时你要的不是一行行的数据,而是它们的汇总。聚合函数把许多行变成一个值:

  • COUNT(*) —— 有多少行
  • SUM(col) —— 总和
  • AVG(col) —— 平均值
  • MIN(col) / MAX(col) —— 最小值 / 最大值
SELECT COUNT(*) FROM student;

COUNT、SUM、AVG 把整列数据各自压成一个数字

Handout

Log in or create account · ⁨登录或创建账户⁩

IGCSE, A-Level · ⁨IGCSE、A-Level⁩ & AP · ⁨与 AP⁩