想求一组数据的平均数,但遇到空时不知道怎么处理
tab1
code js1 js2 js3 ave
A1 10 12 14 12
A2 31 32 30 31
A3 26 28
想要的结果如下
code js1 js2 js3 ave
A1 10 12 14 12
A2 31 32 30 31
A3 26 28 27
请指点,谢谢!
------解决思路----------------------
select *,avg(isnull(js1,0)+isnull(js2,0)+isnull(js3,0)) from tb
------解决思路----------------------
SELECT code,js1,js2,js3你试下
,(ISNULL(js1,0)+ISNULL(js2,0)+ISNULL(js3,0))/
CASE WHEN js1 IS NULL AND js2 IS NULL AND js3 IS NULL THEN 1
ELSE (ISNULL(POWER(js1,0),0)+ISNULL(POWER(js2,0),0)+ISNULL(POWER(js3,0),0)) END ave
FROM TB