簡體   English   中英

使用 Oracle SQL 獲得多列的總數

[英]get total of multiple columns using Oracle SQL

我在如何獲取每行 Amount1 - Amount5 列的總數時遇到問題。

我嘗試了以下查詢,但結果始終為 0。

Select ID, Amount1 + Amount2 + Amount3 + Amount4 as total_amount from table

ID 金額1 金額2 金額3 金額4
1 5 5 5 5
2 10 10 10 10
3 15 20 20 20

希望你能在這方面幫助我。

謝謝,

您發布的數據的結果不能為0

SQL> with test (id, amount1, amount2, amount3, amount4) as
  2    (select 1,  5,  5,  5,  5 from dual union all
  3     select 2, 10, 10, 10, 10 from dual union all
  4     select 3, 15, 20, 20, 20 from dual
  5    )
  6  select id,
  7         amount1 + amount2 + amount3 + amount4 as total_amount
  8  from test
  9  order by id;

        ID TOTAL_AMOUNT
---------- ------------
         1           20
         2           40
         3           75

SQL>

因此,要么你做錯了什么,要么沒有發布我們應該知道的所有幫助。

也許您對同一個用戶使用兩個連接; 一方面,您將所有amount列的舊值更新為您發布的內容,但實際運行select語句的值仍然0 ,因為 - 在第一個 session 中 - 您沒有COMMIT

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM