~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to docs/having.rst

  • Committer: Monty Taylor
  • Date: 2011-02-13 17:26:39 UTC
  • mfrom: (2157.2.2 give-in-to-pkg-config)
  • mto: This revision was merged to the branch mainline in revision 2166.
  • Revision ID: mordred@inaugust.com-20110213172639-nhy7i72sfhoq13ms
Merged in pkg-config fixes.

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:
7
 
 
8
 
.. code-block:: mysql
 
6
SQL HAVING Syntax: ::
9
7
 
10
8
        SELECT column_name, aggregate_function(column_name)
11
9
        FROM table_name
33
31
| 6       |2011-01-03    | Food         |20           |175       |
34
32
+---------+--------------+--------------+-------------+----------+
35
33
 
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
 
34
In order to find if any users have spent more than $100 on recreational activities, use the following SQL statement: ::
39
35
 
40
36
        SELECT userID,SUM(ActivityCost) FROM Activities
41
37
        GROUP BY userID
51
47
 
52
48
Now we want to find if userIDs "131", "256", or "175" spent less than $50 on Activities.
53
49
 
54
 
We add an ordinary WHERE clause to the SQL statement:
55
 
 
56
 
.. code-block:: mysql
 
50
We add an ordinary WHERE clause to the SQL statement: ::
57
51
 
58
52
        SELECT userID,SUM(ActivityCost) FROM Activities
59
53
        WHERE userID='131' OR userID='256' OR userID="175"