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