case when 怎么把null变成0?

sunkess 2015-05-16 12:22:13
  use Student
go
select xh ,xm , ssx,
(select count(*) from sctab where xh =stab.xh) 选课门数,
(select avg(case cj when null then 0 else cj end) from sctab where xh=stab.xh) 平均成绩
from stab


case when 怎么把null变成0?stab的学生信息表里,有同学没有选课 所以他们成绩就是null,可以变成0吗?

我这样写好像不起作用。 谢谢大家了。

...全文
507 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
sunkess 2015-05-16
  • 打赏
  • 举报
回复
引用 1 楼 mxbing1984 的回复:
use Student go select xh ,xm , ssx, (select count(*) from sctab where xh =stab.xh) 选课门数, isnull( (select avg(case cj when null then 0 else cj end) from sctab where xh=stab.xh) ,0)平均成绩 from stab
谢谢!可以了。还想请问 isnull的用法,书上没有提及
ダ雨夹雪リ 2015-05-16
  • 打赏
  • 举报
回复
use Student go select xh ,xm , ssx, (select count(*) from sctab where xh =stab.xh) 选课门数, isnull( (select avg(case cj when null then 0 else cj end) from sctab where xh=stab.xh) ,0)平均成绩 from stab
ダ雨夹雪リ 2015-05-16
  • 打赏
  • 举报
回复
ISNULL(A,B) 如果A的值为null就返回B

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧