Sunteți pe pagina 1din 47

Aggregate Functions

Aggregate functions are typically used in arithmetic expressions. Aggregate func


tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m

ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme

nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in

the GROUP BY clause:


SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;

Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00

107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions

Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of

rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table

GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega

te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func

tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o

n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.

Aggregates and GROUP BY


If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID

FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
----------------

5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00

Aggregates in the Select List


Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates

uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:

SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)

---------- ---------------101 2100.00


107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s

tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac

h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:

SELECT Product_ID, SUM(Total_Sales)


FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei

ther all other


columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_

Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m

ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme

nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in

the GROUP BY clause:


SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;

Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00

107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions

Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of

rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table

GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega

te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func

tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o

n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.

Aggregates and GROUP BY


If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID

FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
----------------

5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00

Aggregates in the Select List


Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates

uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:

SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)

---------- ---------------101 2100.00


107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s

tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac

h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:

SELECT Product_ID, SUM(Total_Sales)


FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei

ther all other


columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_
Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_

Aggregate Functions
Aggregate functions are typically used in arithmetic expressions. Aggregate func
tions operate
on a group of rows and return a single numeric value in the result table for eac
h group.
In the following statement, the SUM aggregate function operates on the group of
rows defined
by the Sales_Table table:
SELECT SUM(Total_Sales)
FROM Sales_Table;
Sum(Total_Sales)
---------------5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in m
ultiple
result values. In the following statement, the SUM aggregate function operates o
n groups of
rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales)
FROM Sales_Table
GROUP BY Product_ID;
Product_ID Sum(Total_Sales)
---------- ---------------101 2100.00
107 1000.40
102 2092.00
Aggregates in the Select List
Aggregate functions are normally used in the expression list of a SELECT stateme
nt and in the
summary list of a WITH clause.
Aggregates and GROUP BY
If you use an aggregate function in the select list of an SQL statement, then ei
ther all other
columns occurring in the select list must also be referenced by means of aggrega
te functions or
their column name must appear in a GROUP BY clause. For example, the following s
tatement
Chapter 8: Aggregate Functions
Aggregate Functions
216 SQL Functions, Operators, Expressions, and Predicates
uses an aggregate function and a column in the select list and references the co
lumn name in
the GROUP BY clause:
SELECT COUNT(*), Product_ID
FROM Sales_

S-ar putea să vă placă și