fifthly day

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).
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值