Examples: HAVING Clause - Teradata Vantage

Teradata® VantageCloud Lake

Deployment
VantageCloud
Edition
Lake
Product
Teradata Vantage
Published
January 2023
ft:locale
en-US
ft:lastEdition
2024-12-11
dita:mapPath
phg1621910019905.ditamap
dita:ditavalPath
pny1626732985837.ditaval
dita:id
phg1621910019905

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;