~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to docs/having.rst

  • Committer: Brian Aker
  • Date: 2011-02-17 10:09:00 UTC
  • mfrom: (2173.2.1 clean-include-usuage)
  • Revision ID: brian@tangent.org-20110217100900-4tpuxxzdl1sj00sh
Merge Monty for headers.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 
4
4
The WHERE keyword cannot be used with aggregate functions, but the HAVING clause can be; this is its primary use.
5
5
 
6
 
SQL HAVING Syntax: ::
 
6
SQL HAVING Syntax:
 
7
 
 
8
.. code-block:: mysql
7
9
 
8
10
        SELECT column_name, aggregate_function(column_name)
9
11
        FROM table_name
31
33
| 6       |2011-01-03    | Food         |20           |175       |
32
34
+---------+--------------+--------------+-------------+----------+
33
35
 
34
 
In order to find if any users have spent more than $100 on recreational activities, use the following SQL statement: ::
 
36
In order to find if any users have spent more than $100 on recreational activities, use the following SQL statement:
 
37
 
 
38
.. code-block:: mysql
35
39
 
36
40
        SELECT userID,SUM(ActivityCost) FROM Activities
37
41
        GROUP BY userID
47
51
 
48
52
Now we want to find if userIDs "131", "256", or "175" spent less than $50 on Activities.
49
53
 
50
 
We add an ordinary WHERE clause to the SQL statement: ::
 
54
We add an ordinary WHERE clause to the SQL statement:
 
55
 
 
56
.. code-block:: mysql
51
57
 
52
58
        SELECT userID,SUM(ActivityCost) FROM Activities
53
59
        WHERE userID='131' OR userID='256' OR userID="175"