oracle 如何在Appex中使用JOIN执行UPDATE语句以计算属性[duplicate]

5us2dqdw  于 2023-02-21  发布在  Oracle
关注(0)|答案(1)|浏览(124)
    • 此问题在此处已有答案**:

Update statement with inner join on Oracle(15个答案)
How can I do an UPDATE statement with JOIN in Appex [duplicate](2个答案)
51分钟前关闭。

I want to calculate the sum of value + service fees from a table booking and bill


and the table of bill
CREATE TABLE BILL (BILL_NUM ,SERVICE_FEES,TOTAL_AMOUNT 
BILL_DATE ,BOOKING_NUM number REFERENCES BOOKING(BOOKING_NUM)
)

我的预订表包含以下属性:(返回日期、预订日期、参考客户(客户 * 编号)、参考位置(位置 * 编号)、参考保险(保险 * 编号)、预订 * 编号、参考汽车(汽车注册编号)、金额

UPDATE BILL AS A
JOIN BOOKING AS B ON A.Booking_num = B.Booking_num 
SET A.Total_Amount = B.amount + A.Service_Fees;

请帮助我修复错误

xriantvc

xriantvc1#

像这样?

update bill a set
  a.total_amount = (select b.amount + a.service_fees
                    from booking b
                    where b.booking_num = a.booking_num
                   )
where exists (select null
              from booking c
              where c.booking_num = a.booking_num
             );

或者,使用merge(更简单):

merge into bill a
  using booking b
  on (a.booking_num = b.booking_num)
when matched then update set
  a.total_amount = b.amount + a.service_fees;

相关问题