Limitations of DISTINCT Aggregates
•
There is no limit to the number of distinct aggregates.
•
Distinct STDDEV and distinct VARIANCE are not supported with multiple distinct
aggregates. For example, this statement will result in an error.
SELECT sum(distinct a), stddev(distinct b) from T group by d;
Examples of Multiple Distinct Aggregates
•
This statement contains distinct aggregates:
SELECT sum(distinct a), count(distinct b), avg(distinct c)
from T group by d;
•
This statement does not contain multiple distincts. Since each distinct aggregate is on the
same column (a), this is treated as one distinct value.
SELECT sum(distinct a), count(distinct a), avg(distinct a)
from T group by d;
•
This statement shows that multiple distinct aggregates can be used with non distinct
aggregates:
SELECT sum(distinct a), avg(distinct b), sum(c)
from T group by d;
Considerations for Select List
•
The * and corr.* forms of a select-list specification are convenient. However, such
specifications make the order of columns in the SELECT result table dependent on the order
of columns in the current definition of the referenced tables or views.
•
A col-expr is a single column name or a derived column. A derived column is an SQL
value expression; its operands can be numeric, string, datetime, or interval literals, columns,
functions (including aggregate functions) defined on columns, scalar subqueries, CASE
expressions, or CAST expressions. Any single columns named in col-expr must be from
tables or views specified in the FROM clause. For a list of aggregate functions, see
(Set) Functions" (page
•
If col-expr is a single column name, that column of the SELECT result table is a named
column. All other columns are unnamed columns in the result table (and have the (EXPR)
heading) unless you use the AS clause to specify a name for a derived column.
Considerations for SEQUENCE BY
If you include both SEQUENCE BY and GROUP BY clauses in the same SELECT statement, the
values of the sequence functions must be computed first and then become input for the aggregate
functions in the statement. For more information, see
The RANDOM function cannot be part of the SEQUENCE BY clause of a sampling method.
Considerations for GROUP BY
•
If you include a GROUP BY clause, the columns you refer to in the select-list must be
either grouping columns or arguments of an aggregate (or set) function. For example, if
AGE is not a grouping column, you can refer to AGE only as the argument of a function,
such as AVG (AGE).
•
The expression in the GROUP BY clause must be exactly the same as the expression in the
select list. An error will be returned if it is not. It cannot contain aggregate functions or
subqueries.
•
If the value of col-expr is a numeric constant, it refers to the position of the select list item
and is treated as the current GROUP BY using the ordinal feature.
279).
"SEQUENCE BY Clause" (page
SELECT Statement
"Aggregate
268).
153