About Aggregate Function
1
An aggregate function basically combines multiple rows into a single number. Aggregate functions can be
used to count the number of rows, find the sum or average of all the values in a given numeric column, and find
the largest or smallest of the entries in a given column. In SQL, these aggregate functions are: COUNT, SUM,
AVG, MAX, MIN, and so forth.
The COUNT function is used to count how many (rows) of something there are, or the number of rows in a result
set. Following is the general syntax for the COUNT function.
SELECT COUNT(*)
FROM Table-name(s)
如果我们想找出对某列中的数值项求和
SELECT SUM(column_name) AS [column_name]
FROM Employee
2
Row-Level Functions
Row-level "function" can be used to perform an arithmetic operation on a column.
for example
SELECT wage, (wage + 5) AS [wage + 5]
FROM Employee
the result is
wage wage + 5
------------ ------------
10.0000 15.0000
15.0000 20.0000
18.0000 23.0000
NULL NULL
20.0000 25.0000
note that Strictly speaking a row-level "function" is not a function, but an operation performed in a result set. But
the use of arithmetic operations in result sets behaves like functions
3
The ROUND Function
The ROUND function rounds numbers to a specified number of decimal places.
for example
SELECT names, wage, ROUND((wage/3), 2) AS [wage/3]
FROM Employee
This query produces the following output:
names wage wage/3
-------------------- --------------------- ---------------------
Sumon Bagui 10.00 3.33
Sudip Bagui 15.00 5.00
Priyashi Saha 18.00 6.00
Ed Evans NULL NULL
Genny George 20.00 6.67
In this example, the values of (wage/3) are rounded up to two decimal
places because of the "2" after the comma after ROUND(wage/3).