gpt4 book ai didi

sql - 用新条目更新表列

转载 作者:行者123 更新时间:2023-12-04 03:52:52 25 4
gpt4 key购买 nike

我正在使用Oracle APEX,并且希望使用下表中的新值更新报告中的列。报告查询如下图所示。

TABLE  "VENDOR_ACCOUNT" 
( "VEN_ACCOUNTID" NVARCHAR2(10),
"VEN_REGNO" NVARCHAR2(10),
"VEN_TXDATE" DATE,
"VEN_INVOICE_REFNO" NVARCHAR2(10),
"TOTALAMOUNT" NVARCHAR2(10),
"IN" NUMBER(10,0),
"OUT" NUMBER(10,0)
)

SELECT "VEN_ACCOUNTID" ,
"VEN_REGNO" ,
"VEN_TXDATE" ,
"VEN_INVOICE_REFNO" ,
"TOTALAMOUNT" ,
"IN",
"OUT",
"TOTALAMOUNT"+"IN" as "CREDIT",
"TOTALAMOUNT"-"OUT" as "DEBIT"
FROM Vendor_Account;

所需方案:我想用 TotalAmountDebit更新 Credit列。新的 DebitCredit值必须在下一条记录的 TotalBalance列中显示。

最佳答案

您可以使用Oracle分析函数LAG:

Select "VEN_ACCOUNTID" , 
"VEN_REGNO" ,
"VEN_TXDATE" ,
"VEN_INVOICE_REFNO" ,
"TOTALAMOUNT" ,
"TOTALAMOUNT" + lag("IN",1) over (ORDER BY "VEN_ACCOUNTID")
- lag("OUT",1) over (ORDER BY "VEN_ACCOUNTID") AS "NEW_TOTALAMOUNT",
"IN",
"OUT",
"TOTALAMOUNT"+"IN" as "CREDIT",
"TOTALAMOUNT"-"OUT" as "DEBIT"
FROM Vendor_Account;

关于sql - 用新条目更新表列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14748157/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com