sql sum不同的列值降序

时间:2012-08-07 01:36:47

标签: sql sql-server sql-server-2008

我有这个问题:

 Available Total Usage

7000.0     7021.9
7000.0    -15000.00
7000.0    -7700.85

我想创建新列以按降序对两列进行求和。我希望的结果是

Available         Total Usage         Total
7000.0    7021.9 -700.85+(-15000.00) = -15700.85
7000.0    -15000.00 7000+(-7700.85)  = -700.85
7000.0    -7700.85  7000

我该怎么做?

1 个答案:

答案 0 :(得分:0)

试试这个:

with cte as(select Available, [Total Usage], Available+[Total Usage] as Total from <table>)
select * from CTE order y Total