sql 多列求和

列相加即可
注意Null不可加,先用ISNULL方法验证,设置默认值

SELECT  ID,
        Name,
        Province,
        City,
        District,
        ISNULL(row1, 0),
        ISNULL(row2, 0),
        ISNULL(row3, 0),
        ISNULL(row4, 0),
        ISNULL(row5, 0) + ISNULL(row6, 0) + ISNULL(row7, 0)
        + ISNULL(row8, 0) AS 'total'
FROM    O WITH(NOLOCK)
    原文作者:Lulus
    原文地址: https://www.jianshu.com/p/5facffd3d3c8
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞