Updated on 2024-07-18 GMT+08:00

Analysis Statements - GROUP BY

Groups data by field value.

Grouping by Field Value

SELECT age GROUP BY age
Table 1 Grouping by field value

age

28

32

36

Grouping by Field Alias

SELECT account_number AS num GROUP BY num
Table 2 Grouping by field alias

num

1

16

13

18

Grouping by Multiple Fields

SELECT account_number AS num, age GROUP BY num, age
Table 3 Grouping by multiple fields

num

age

1

32

16

36

13

28

18

32

Using SQL Functions

For details about functions, see Function.

SELECT LENGTH(lastname) AS len, COUNT(*) AS count GROUP BY LENGTH(lastname)
Table 4 Using SQL functions

len

count

4

2

5

2