Skip to content · ⁨コンテンツへスキップ⁩

Grouping with GROUP BY · ⁨GROUP BYによるグループ化⁩

English

Grouping rows with GROUP BY

An aggregate like AVG normally summarises the whole table into one number. GROUP BY splits the rows into groups that share a value, and gives one summary row per group:

This gives one row for each form, with that form's count and average.

日本語

GROUP BY による行のグループ化

AVG のような集計関数は通常、全体の表を単一の数値に要約します。GROUP BY は共有する値を持つ行をグループに分割し、グループごとに1行ずつ要約結果を返します:

SELECT form, COUNT(*) AS n, ROUND(AVG(score), 2) AS avg_score
FROM student
GROUP BY form;

これにより、各 form に対して1行ずつ返され、そのクラスの人数と平均が含まれます。

GROUP BY は共有する値を持つ行をグループごとに1行に圧縮し、残りの値を合計します

Handout · ⁨プリント⁩

Log in or create account · ⁨ログインまたはアカウント作成⁩

IGCSE, A-Level & AP