Examples: HAVING Clause - Teradata Database - Teradata Vantage NewSQL Engine

SQL Data Manipulation Language

Product
Teradata Database
Teradata Vantage NewSQL Engine
Release Number
16.20
Published
March 2019
Language
English (United States)
Last Update
2019-05-03
dita:mapPath
fbo1512081269404.ditamap
dita:ditavalPath
TD_DBS_16_20_Update1.ditaval
dita:id
B035-1146
lifecycle
previous
Product Category
Teradata Vantage™

The following example shows the use of HAVING as applied to the aggregate results of a single group defined in the SELECT list, which is particularly useful in a SELECT subquery.

     SELECT COUNT(employee)
     FROM department
     WHERE dept_no = 100
     HAVING COUNT(employee) > 10;

The following SELECT statements are additional examples of the correct use of the HAVING clause.

     SELECT SUM(t.a)
     FROM t,u
     HAVING SUM(t.a)=SUM(u.a);
     SELECT SUM(t.a), SUM(u.a)
     FROM t,u
     HAVING SUM(t.b)=SUM(u.b);
     SELECT SUM(t.a)
     FROM t,u
     HAVING SUM(t.b)=SUM(u.b)
     AND    u.b = 1
     GROUP BY u.b;