Calculates the numeric average of all (distinct) values.
avg([all | distinct] expression)
select avg(advance), sum(total_sales) from titles where type = "business"
------------------------ ----------- 6,281.25 30788
select type, avg(advance), sum(total_sales) from titles group by type
type ------------ ------------------------ ----------- UNDECIDED NULL NULL business 6,281.25 30788 mod_cook 7,500.00 24278 popular_comp 7,500.00 12875 psychology 4,255.00 9939 trad_cook 6,333.33 19566
select pub_id, sum(advance), avg(price) from titles group by pub_id having sum(advance) > $25000 and avg(price) > $15
pub_id ------ -------------------- -------------------- 0877 41,000.00 15.41 1389 30,000.00 18.98
avg, an aggregate function, finds the average of the values in a column. avg can only be used on numeric (integer, floating point, or money) datatypes. Null values are ignored in calculating averages.
When you average (signed or unsigned) int, smallint, tinyint data, the SAP ASE server returns the result as an int value. When you average (signed or unsigned) bigint data, the SAP ASE server returns the result as a bigint value. To avoid overflow errors in DB-Library programs, declare variables used for resultrs appropriately.
You cannot use avg with the binary datatypes.
Since the average value is only defined on numeric datatypes, using avg Unicode expressions generates an error.
See also Transact-SQL Users Guide.
ANSI SQL – Compliance level: Transact-SQL extension.
Any user can execute avg.