我想在两个不同的表中使用两个值作为第三个表中的总计。
例如:
accommodation
和flight
acc_price
flight_price
添加值
reservation.reservation_total
我尝试过的事情;
SELECT F.FLI_PRICE + AC.ACC_PRICEPN
INTO R.SUBTOTAL
FROM HOLIDAY_RESERVATION R, FLIGHT F, ACCOMMODATION AC;
UPDATE HOLIDAY_RESERVATION HR
SET SUBTOTAL = (SELECT SUM (T.PRICE) FROM ( SELECT ACC_PRICEPN PRICE FROM ACCOMMODATION A
WHERE A.ACC_ID = HR.ACC_ID)
UNION ALL
SELECT FLI_PRICE PRICE FROM FLIGHT F1
WHERE HR.IN_FLIGHT_ID = F1.FLI_ID
UNION ALL
SELECT FLI_PRICE PRICE FROM FLIGHT F2
WHERE HR.OUT_FLIGHT_ID = F2.FLI_ID
) T
);
答案 0 :(得分:2)
使用SELECT INTO
的{{1}}声明....这肯定会解决您的问题............
答案 1 :(得分:0)
通过“添加要在表reservation.reservation_total中使用的那些值”,您是否要在预订的reservation_total列中插入添加的值? 如果是这样,您可以使用:
insert into reservation(rowid,reservation_total) values (id,select acc_price +
flight_price from accomodation, flight where <some condition> )