Reputation: 2084
I want to add two columns values of my table and sort it in descending order. E.g:
int_id int_test_one int_test_2
1 25 13
2 12 45
3 25 15
Considering the table above, I want a SQL query which give me the result like below:
int_id sum(int_test_one,int_test_two)
2 57
3 40
1 38
Is there any sql query to do this?
Upvotes: 4
Views: 102338
Reputation: 38615
Did you try what you describe? This works:
SELECT int_id , ( int_test_one + int_test_two ) as s FROM mytable ORDER BY s DESC
You can ommit the "as" keyword if you want.
Upvotes: 3
Reputation: 17382
Try this
SELECT
int_id,
(int_test_one + int_test_two) AS [Total]
FROM
mytable
ORDER BY
[Total] DESC
Upvotes: 1
Reputation: 28834
There is not built in function for this kind of horizontal aggregation, you can just do...
SELECT INT_ID, INT_TEST_ONE + INT_TEST_TWO AS SUM FROM TABLE
Upvotes: 12