oracle对三个列求sum

版权声明:本文为yissan原创文章,未经本人允许严禁转载! https://blog.csdn.net/yissan/article/details/73947130

oracle数据库对test_table表的三个列count1,count2,count3求sum的两种sql,做个记录

  • 第一种
select sum (case when count1 is not null then count1 when 
count2 is not null then count2 when count3 is not null 
then count3 else '0' end ) a from test_table
  • 第二种
select sum(decode(count1,null,0,count1) +decode(count2,null,0,count2)
+decode(count3,null,0,count3)) a from test_table

猜你喜欢

转载自blog.csdn.net/yissan/article/details/73947130