~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to docs/having.rst

  • Committer: Lee Bieber
  • Date: 2011-01-15 03:08:27 UTC
  • mfrom: (1994.5.38 doc)
  • mto: This revision was merged to the branch mainline in revision 2087.
  • Revision ID: kalebral@gmail.com-20110115030827-0h9s99kiknrmt9ti
Merge Stewart - some documentation clean up

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
**SQL HAVING Example**
15
15
 
16
16
Take a look at the "Activities" table:
17
 
 
18
 
+---------+--------------+--------------+-------------+----------+
19
 
|Id       |ActivityDate  |ActivityType  |ActivityCost | userID   |
20
 
+=========+==============+==============+=============+==========+
21
 
| 1       |2011-01-02    | Sport        |45           |131       |
22
 
+---------+--------------+--------------+-------------+----------+
23
 
| 2       |2011-01-02    | Art          |10           |256       |
24
 
+---------+--------------+--------------+-------------+----------+
25
 
| 3       |2011-01-02    | Music        |25           |022       |
26
 
+---------+--------------+--------------+-------------+----------+
27
 
| 4       |2011-01-02    | Food         |125          |022       |
28
 
+---------+--------------+--------------+-------------+----------+
29
 
| 5       |2011-01-03    | Music        |40           |131       |
30
 
+---------+--------------+--------------+-------------+----------+
31
 
| 6       |2011-01-03    | Food         |20           |175       |
 
17
 
 
18
+---------+--------------+--------------+-------------+----------+
 
19
|Id       |ActivityDate  |ActivityType  |ActivityCost | userID   |
 
20
+=========+==============+==============+=============+==========+
 
21
| 1       |2011-01-02    | Sport        |45           |131       |
 
22
+---------+--------------+--------------+-------------+----------+
 
23
| 2       |2011-01-02    | Art          |10           |256       |
 
24
+---------+--------------+--------------+-------------+----------+
 
25
| 3       |2011-01-02    | Music        |25           |022       |
 
26
+---------+--------------+--------------+-------------+----------+
 
27
| 4       |2011-01-02    | Food         |125          |022       |
 
28
+---------+--------------+--------------+-------------+----------+
 
29
| 5       |2011-01-03    | Music        |40           |131       |
 
30
+---------+--------------+--------------+-------------+----------+
 
31
| 6       |2011-01-03    | Food         |20           |175       |
32
32
+---------+--------------+--------------+-------------+----------+
33
33
 
34
34
In order to find if any users have spent more than $100 on recreational activities, use the following SQL statement: ::
39
39
 
40
40
The result-set will look like this:
41
41
 
42
 
======    ===============
43
 
userID    SUM(OrderPrice)
44
 
======    ===============            
45
 
022       150                  
 
42
======    ===============
 
43
userID    SUM(OrderPrice)
 
44
======    ===============
 
45
022       150
46
46
======    ===============
47
47
 
48
48
Now we want to find if userIDs "131", "256", or "175" spent less than $50 on Activities.
56
56
 
57
57
The result-set would be:
58
58
 
59
 
======    ===============
60
 
userID    SUM(OrderPrice)
61
 
======    ===============            
 
59
======    ===============
 
60
userID    SUM(OrderPrice)
 
61
======    ===============
62
62
256       10
63
 
175       20                  
 
63
175       20
64
64
======    ===============