~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to docs/groupby.rst

GROUP BY clause with example

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Group By
 
2
========
 
3
 
 
4
The GROUP BY clause is used to extract only those records that fulfill a specified criterion.
 
5
 
 
6
SQL GROUP BY Syntax ::
 
7
 
 
8
        SELECT column_name, aggregate_function(column_name)
 
9
        FROM table_name
 
10
        WHERE column_name operator value
 
11
        GROUP BY column_name
 
12
 
 
13
        
 
14
WHERE Clause Example
 
15
 
 
16
The "Activities" table:
 
17
 
 
18
+---------+--------------+-------------+----------+
 
19
|Id       |ActivityDate  |ActivityType |User      |
 
20
+=========+==============+=============+==========+
 
21
| 1       |              | Sue         |Larson    | 
 
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
+---------+--------------+-------------+----------+
 
33
 
 
34
If you want to select only the persons living in the city "Chicago" from the table above, use the following SELECT statement: ::
 
35
 
 
36
        SELECT * FROM Persons
 
37
        WHERE City='Chicago'
 
38
 
 
39
The result-set will look like this:
 
40
 
 
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'