我想添加我的表的两列值并按降序排序。 E.g:sql查询添加列值
int_id int_test_one int_test_2
1 25 13
2 12 45
3 25 15
考虑上面的表格,我想一个SQL查询这给我结果如下图所示:
int_id sum(int_test_one,int_test_two)
2 57
3 40
1 38
是否有任何SQL查询来做到这一点?
我想添加我的表的两列值并按降序排序。 E.g:sql查询添加列值
int_id int_test_one int_test_2
1 25 13
2 12 45
3 25 15
考虑上面的表格,我想一个SQL查询这给我结果如下图所示:
int_id sum(int_test_one,int_test_two)
2 57
3 40
1 38
是否有任何SQL查询来做到这一点?
没有内置的功能,对于这种水平的聚集,你可以做...
SELECT INT_ID, INT_TEST_ONE + INT_TEST_TWO AS SUM FROM TABLE
你试过你描述的吗?此作品:
SELECT int_id , (int_test_one + int_test_two) as s FROM mytable ORDER BY s DESC
如果需要,可以省略“as”关键字。
不要忘了DESC顺序:) – AdaTheDev 2010-02-08 09:12:16
试试这个
SELECT
int_id,
(int_test_one + int_test_two) AS [Total]
FROM
mytable
ORDER BY
[Total] DESC
忘记降序排序 – David 2010-02-08 09:20:27