~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to docs/having.rst

  • Committer: Lee Bieber
  • Date: 2011-02-16 03:48:03 UTC
  • mfrom: (2165.2.6 trunk-docs-fixes)
  • mto: This revision was merged to the branch mainline in revision 2173.
  • Revision ID: kalebral@gmail.com-20110216034803-bknjc8l6i4e3vyka
Merge Andrew - 718657: Several errors in Date/Time docs

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"