4
The GROUP BY clause is used to extract only those records that fulfill a specified criterion.
8
SELECT column_name, aggregate_function(column_name)
10
WHERE column_name operator value
16
The "Activities" table:
18
+---------+--------------+-------------+----------+
19
|Id |ActivityDate |ActivityType |User |
20
+=========+==============+=============+==========+
22
+---------+--------------+-------------+----------+
23
| 2 | Roberts | Teri |Roberts |
24
+---------+--------------+-------------+----------+
25
| 3 | Peterson | Kari |Peterson |
26
+---------+--------------+-------------+----------+
27
| 4 | Larson | Sue |Smith |
28
+---------+--------------+-------------+----------+
29
| 5 | Roberts | Teri |Dagwood |
30
+---------+--------------+-------------+----------+
31
| 6 | Peterson | Kari |Masters |
32
+---------+--------------+-------------+----------+
34
If you want to select only the persons living in the city "Chicago" from the table above, use the following SELECT statement: ::
39
The result-set will look like this:
41
+---------+------------+----------+----------+--------+
42
| Id |LastName |FirstName |Address |City |
43
+---------+------------+----------+----------+--------+
44
|1 | Larson | Sue |3 Cherry | Chicago|
45
+---------+------------+----------+----------+--------+
46
|2 | Roberts | Teri |21 Brown | Chicago|
47
+---------+------------+----------+----------+--------+
b'\\ No newline at end of file'