最佳答案
我想得到 column 1的 sum,column 2的 sum 和 total sum。在 Postgres,我可以这样做:
SELECT *, a+b AS total_sum FROM
(
SELECT SUM(column1) AS a, SUM(column2) AS b
FROM table
)
但在 Oracle 中,我得到了一个语法错误,必须使用以下代码:
SELECT a,b, a+b AS total_sum FROM
(
SELECT SUM(column1) AS a, SUM(column2) AS b
FROM table
)
我有很多列要返回,所以我不想在主查询中再次写列名。有什么简单的解决办法吗?
我不能在内部查询中使用 a + b,因为在这个位置没有已知的值。
我不想使用 SELECT SELECT SUM(column1) AS a, SUM(column2) AS b, SUM(column1)+SUM(column2) AS total_sum
。