当前位置: 代码迷 >> Sql Server >> case when 如何把null变成0
  详细解决方案

case when 如何把null变成0

热度:23   发布时间:2016-04-24 09:05:54.0
case when 怎么把null变成0?
本帖最后由 SUNKESS 于 2015-05-16 12:24:06 编辑
  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吗? 

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


------解决思路----------------------
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
  相关解决方案