~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to docs/having.rst

  • Committer: Andrew Hutchings
  • Date: 2011-02-15 22:03:42 UTC
  • mto: (2172.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 2173.
  • Revision ID: andrew@linuxjedi.co.uk-20110215220342-k4tveraug3bpy2v5
Make fixes to temporal docs
Make a few minor docs cleanups/fixes
Start using syntax-highlighting code blocks

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"