在一行中添加列的值

时间:2014-09-27 08:38:50

标签: sql-server-2008

我想在多列中添加一行的值作为列

    No Name Requested Reported Finished
    1  Ali     4        4         1
    2  Amina   10       5         2

    As

    No Name Requested Reported Finished Total
    1  Ali     4        4         1       9
    2  Amina   10       5         2       17

2 个答案:

答案 0 :(得分:0)

使用SUM功能。

<强>查询

SELECT no,Name,requested,reported,finished,
SUM(requested+reported+finished) AS Total
FROM tbl
GROUP BY no,Name,requested,reported,finished;

Fiddle Demo

答案 1 :(得分:0)

SELECT no,
       Name,
       requested,
       reported,
       finished,
       Isnull(requested, 0) + Isnull(reported, 0) + Isnull(finished, 0) AS Total
FROM tbl