空值NULL处理

--1.空值(null)处理

--查询籍贯为NULL同学

--如果判断一个字段的的值是不是null,需要使用is关键字, 不能使用=

select * from TbStudent where stuAddress is null

 

--查询籍贯不是null的所有同学

select * from TbStudent where stuAddress is not null

 

--注意:not like ,is not

--查询所有同学信息,如果籍贯是null,就用’未知‘替代

--ISNULL(原始数据,代替值)函数

select stuName,stuNumber,ISNULL (sstuAddress,'未知')from TbStudent

 

--查询所有数学成绩为null的学生

select * from TbStudent where stuMath is null

--查询所有学生的考试成绩,如果为null,则用’缺考‘代替

select stuName,stuNumber,ISNULL(stuMath,'缺考') from TbStudent

--stuMath是int类型,’缺考‘是varchar类型的,所以不允许填充到同一列上

--数据表中任何一列,都只能存储一种数据类型的数

select stuName,stuNumber,stuMath from TbStudent

--SQL里的NULL和c#里的NULL是不一样的

--c#里的NULl:表示一个引用类型的变量,不指向堆上的任何对象

--SQL里的NULL:unknown,不知道。SQL里的任意数据类型的字段,都可以赋值null

--SQL里NULL与任何数据做运算,结果还是null

--查询所有的学生的数学成绩,并且给所有人的学习成绩+10分

select stuName,stuNumber,stuMath+10 as '数学' from TbStudent

--为啥不让用 = null,只能用 is null

 

 

--查询所有学生的考试成绩,如果为null,则用’缺考‘代替

select stuName,stuNumber,ISNULLCAST(stuMath as varchar(4)),'缺考') from TbStudent

 

--注意:这个ISNULL()函数,不会修改原表中的数据,它只是把查询结果集中的

--显式方式变了变

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值