sql 中isnull函数的用法

来源:百度知道 编辑:UC知道 时间:2024/06/27 05:14:25
declare @t table
(
id int identity(1,1),
UserId varchar(10),
Odds int
)

insert @t select 'a',12
union all select 'b',23
union all select 'c',34

select
isnull(userid,'total') as userid,
sum(odds) as odds
from @t
group by userid
with rollup

/**
userid odds
--------------
a 12
b 23
c 34
total 69
**/
大家帮我看看这段代码是什么意思啊!尤其是isnull和with rollup谢谢大家了!

1,语法 :

ISNULL ( check_expression , replacement_value )

2,参数 :

check_expression**

将被检查是否为 NULL的表达式。check_expression 可以是任何类型的。

replacement_value

在 check_expression 为 NULL时将返回的表达式。replacement_value 必须与check_expresssion 具有相同的类型。

3,返回类型 :

返回与 check_expression 相同的类型。

4,注释 :

如果 check_expression 不为 NULL,那么返回该表达式的值;否则返回 replacement_value。

5,示例 :

将 ISNULL 与 AVG 一起使用 

*下面的示例查找所有书的平均价格,用值 $10.00 替换 titles 表的 price 列中的所有 NULL 条目。

USE pubs 

GO 

SELECT AVG(ISNULL(price, $10.00)) 

FROM titles 

GO*

请问SQL中decode函数的用法? sql 中Dateadd()函数的用法 vb 中 isNull()这个函数怎么用阿? sql中日期函数的用法 SQL中CASE的 用法 SQL中 ALL的用法 sql中 in的用法 sql中as的用法 sql中,count的用法. sql中count的用法