添加列值的sql查询
我想在我的表中添加两列值并按降序排序。例如:添加列值的sql查询,sql,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
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 s FROM mytable ORDER BY s DESC
如果需要,您可以使用“as”关键字。这种水平聚合没有内置函数,您只需执行
SELECT INT_ID, INT_TEST_ONE + INT_TEST_TWO AS SUM FROM TABLE
试试这个
SELECT
int_id,
(int_test_one + int_test_two) AS [Total]
FROM
mytable
ORDER BY
[Total] DESC
别忘了描述顺序:)这里有一个最近的好答案