Using Aggregate Functions in The Select List: USE Pubs SELECT SUM (Ytd - Sales) FROM Titles
Using Aggregate Functions in The Select List: USE Pubs SELECT SUM (Ytd - Sales) FROM Titles
Aggregate functions+
An e-.ression that returns the sa(e value for ever) ro, in the result set, such as a constant+
:or (ore infor(ation a/out generating aggregate values for result sets containing (ulti.le ro,s, see
!rou.ing Ro,s ,ith !R"U= >?+
Aggregate functions cannot /e used in a 012R2 clause+ 1o,ever, a S2L2C$ state(ent ,ith aggregate
functions in its select list often includes a 012R2 clause that restricts the ro,s to ,hich the aggregate
function is a..lied+ 'f a S2L2C$ state(ent includes a 012R2 clause (/ut not a !R"U= >? clause), an
aggregate function .roduces a single value for the su/set of ro,s s.ecified /) the 012R2 clause+ $his is
true ,hether it is o.erating on all ro,s in a ta/le or on a su/set of ro,s defined /) a 012R2 clause+
Such a function is called a scalar aggregate+
$his *uer) returns the average advance and the su( of )ear3to3date sales for /usiness /oo4s onl)5
USE pubs
SELECT 234(ad%a.$e)5 SUM(ytd_sales)
FROM titles
67ERE type 8 9busi.ess9
1ere is the result set5
--------- -------
65(:1)(* +;7::
(1 !"(s) a##e$ted)
?ou can use (ore than one aggregate function in the sa(e select list and .roduce (ore than one scalar
aggregate in a single S2L2C$ state(ent+
See Also
Aggregate :unctions
S2L2C$