----------  Having_Clause  ----------

A HAVING clause is used to specify a condition which a group must  satisfy  in
order  to  be  selected.   It  applies  to the most deeply nested group in the
SELECT command, and can only be used when every attribute selected  is  either
grouped, a function (avg, max, etc.), or a constant.  A HAVING clause consists
of boolean expressions, that  is,  expressions  that  evaluate  to  "true"  or
"false".

A HAVING clause may be built up using boolean expressions that are joined  us-
ing "and" and "or".

Syntax:

     having |B_EXPR           |
            |(B_EXPR)         |
            |B_EXPR or B_EXPR |
            |B_EXPR and B_EXPR|
            |not B_EXPR       |

If two boolean expressions are joined by an "and",  both  boolean  expressions
must be true in order for the whole boolean expression to be true.

If two boolean expressions are joined by an "or", either one or  both  boolean
expressions must be true in order for the whole boolean expression to be true.

The "and" operator has precedence over the "or" operator.

A HAVING clause may contain boolean expressions of the form:

     | GP_EXPR [ |is      | ] GP_CONDITION |
     |           |[is] not|                |
     |                                     |
     | null GP_EXPR                        |

A GP_EXPR is: |GP_ATTR                              |
              |STRING                               |
              |NUMBER                               |
              |GP_FUNCTION                          |
              |(GP_EXPR)                            |
              |convert GP_EXPR [to] DATATYPE        |
              |convert GP_EXPR [to] generic DATATYPE|
              |GP_EXPR convert to DATATYPE          |
              |GP_EXPR convert [to] generic DATATYPE|
              |GP_EXPR OPERATOR GP_EXPR             |
              |GP_EXPR OPERATOR                     |
              |OPERATOR GP_EXPR                     |
              |BUILT_IN_FUNCTION                    |
              |USER_DEFINED_FUNCTION                |

A GP_ATTR is either an attribute that appears in a "group by" clause.  If  the
attribute  appears in a "group by" clause, the value of the attribute for each
group is used.

A GP_FUNCTION is a group function on an attribute that does not  appear  in  a
"group  by"  clause.   For  an  attribute that does not appear in a "group by"
clause, a group function such as "count", "avg", "max", "min" or "sum" must be
applied to the attribute over the group.

See under EXPR for OPERATORs and BUILT_IN_FUNCTIONs.

A GP_CONDITION is:

     | | =  | GP_EXPR                                            |
     | | != |                                                    |
     | | >  |                                                    |
     | | >= |                                                    |
     | | <  |                                                    |
     | | <= |                                                    |
     |                                                           |
     | | like    | PATTERN                                       |
     | | match   |                                               |
     | | !match  |                                               |
     | | smatch  |                                               |
     | | !smatch |                                               |
     |                                                           |
     | [ | =  | ] null                                           |
     |   | != |                                                  |
     |                                                           |
     | between GP_EXPR [|exclusive|] [and] GP_EXPR [|exclusive|] |
     |                  |inclusive|                 |inclusive|  |
     |                                                           |
     | range GP_EXPR [|exclusive|] [to] GP_EXPR [|exclusive|]    |
     |                |inclusive|                |inclusive|     |

"Between ... and" is equivalent to "range ... to".  Values  are  inclusive  by
default and must be in increasing order for any groups to meet the condition.

Pattern matching in HAVING clauses is the same as for WHERE clauses.

For further information, enter:

                help select;
                help where_clause;
