Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7693573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:07:14+00:00 2026-05-31T21:07:14+00:00

I am using the following statement; SELECT RESV_ID, BOOKING_CUS_ID, ACC_ID, (SELECT F.FLI_PRICE FROM FLIGHT

  • 0

I am using the following statement;

SELECT RESV_ID, BOOKING_CUS_ID, ACC_ID,
    (SELECT F.FLI_PRICE FROM FLIGHT F WHERE F.FLI_ID = R.IN_FLIGHT_ID) AS DEPART_FLIGHT_PRICE, 
    (SELECT F1.FLI_PRICE FROM FLIGHT F1 WHERE F1.FLI_ID = R.OUT_FLIGHT_ID) AS RETURN_FLIGHT_PRICE, 
    (SELECT AC.ACC_PRICEPN FROM ACCOMMODATION AC WHERE AC.ACC_ID = R.ACC_ID) AS ACCOMMODATION_PRICE
    FROM HOLIDAY_RESERVATION R;

to yield the following results;

   RESV_ID BOOKING_CUS_ID     ACC_ID DEPART_FLIGHT_PRICE RETURN_FLIGHT_PRICE ACCOMMODATION_PRICE
---------- -------------- ---------- ------------------- ------------------- -------------------
         1              1          2                 520                 450                 350
         2              3          4                 250                 150                 150
         3              5          6                 290                 300                 450
         4              7          7                 399                 450                 650
         5              9                            365                 345
         6             11                            558                 460
         7             13                            250                 250
         8             15                            550                 550
         9             17         25                                                         250
        10             19         19                                                         450

10 rows selected.

Question:
How do I sum up the price fields, SOME PRICES ARE NOT AVAILABLE because a reservation was either made for accommodation only or flight only, hence both values will not be present always and this is where the issue lies

DEPART_FLIGHT_PRICE RETURN_FLIGHT_PRICE ACCOMMODATION_PRICE

Furthermore:
I wish to insert or update the SUM of those three values into a SUBTOTAL in the reservation table, perhaps by using select into or update, I have spent a whole day trying to do this but my skills are limited. any help will be greatly appreciated.

Flight table

FLI_ID FLI_CO FLI_AIRCRA DEPT_AIRPORT ARRV_AIRPORT DEPT_TIME                      ARRV_TIME               FLI_PRICE

     1 BD425  Boeing 707            1           12 18-MAR-12 02.24.00 AM          18-MAR-12 06.24.00 AM         520
     2 LX345  Beriev 30             6            7 20-MAR-12 03.30.00 PM          20-MAR-12 04.20.00 PM         250
     3 NZ4445 Boeing 720            9           14 25-MAR-12 09.00.00 AM          25-MAR-12 05.00.00 PM         290
     4 TP351  Boeing 767           10           15 25-MAR-12 11.25.00 AM          25-MAR-12 03.35.00 PM         399
     5 BA472  Boeing 720            5           14 26-MAR-12 01.05.00 PM          26-MAR-12 04.15.00 PM         365

Accommodation

ACC_ID ACC_TYPE_CODE ACC_DESC                                           ACC_PRICEPN  ACC_ROOMS  RESORT_ID ACC_ADDR                          CITY_ID

     1             1 Three bedroom bungalow near theme park                     500          3          1
     2             1 Two bedroom bungalow next to disney house                  350          2          1
     3             1 One bedroom bungalow with lake view                        250          2          2
     4             2 One bedroom chalet near the lake                           150          1          2
     5             2 Four bedroom chalet near the tree house                    600          4          3

Reservation

RESV_ID     EMP_ID BOOKING_CUS_ID RESV_DATE HOLIDAY_S HOLIDAY_E IN_FLIGHT_ID OUT_FLIGHT_ID IN_FLIGHT_SEATS_NO OUT_FLIGHT_SEATS_NO     ACC_ID   SUBTOTAL

     1        338              1 16-FEB-12 18-MAR-12 20-APR-12            1            11                  2                   2          2
     2        335              3 10-JAN-12 20-MAR-12 22-APR-12            2            12                  2                   2          4
     3        338              5 05-MAR-12 25-MAR-12 26-APR-12            3            13                  2                   2          6
     4        328              7 02-JAN-12 25-MAR-12 25-APR-12            4            14                  2                   2          7
     5        311              9 20-JAN-12 26-MAR-12 21-APR-12            5            15                  2                   2
     6        317             11 07-JAN-12 27-MAR-12 22-APR-12            6            16                  2                   2
     7        344             13 29-FEB-12 15-MAR-12 12-APR-12            7            17                  2                   2
     8        326             15 11-JAN-12 18-MAR-12 12-APR-14            8            18                  2                   2
     9        329             17 16-JAN-12 19-MAR-12 17-APR-12                                                                   25
    10        323             19 18-FEB-12 20-MAR-12 21-APR-12                                                                   19

Okay I managed to yield the results that i wanted

SELECT HR.RESV_ID, F_IN.FLI_ID, F_IN.FLI_PRICE, F_OUT.FLI_ID, F_OUT.FLI_PRICE, AC.ACC_ID, AC.ACC_PRICEPN, NVL(F_IN.FLI_PRICE,0)+NVL(F_OUT.FLI_PRICE,0)+NVL(AC.ACC_PRICEPN,0) AS TOTAL
FROM HOLIDAY_RESERVATION HR 
LEFT JOIN FLIGHT F_IN ON HR.IN_FLIGHT_ID = F_IN.FLI_ID
LEFT JOIN FLIGHT F_OUT ON HR.OUT_FLIGHT_ID = F_OUT.FLI_ID
LEFT JOIN ACCOMMODATION AC ON HR.ACC_ID = AC.ACC_ID
ORDER BY HR.RESV_ID;

YIELDS

   RESV_ID     FLI_ID  FLI_PRICE     FLI_ID  FLI_PRICE     ACC_ID ACC_PRICEPN      TOTAL
---------- ---------- ---------- ---------- ---------- ---------- ----------- ----------
         1          1        500         11        555          2         350       1405
         2          2        150         12        253          4         150        553
         3          3        300         13        345          6         450       1095
         4          4        450         14        343          7         650       1443
         5          5        345         15        242                               587
         6          6        460         16        460                               920
         7          7        250         17        250                               500
         8          8        550         18        550                              1100
         9                                                     25         250        250
        10                                                     19         450        450

And the following statement is to update the reservation table.
Thanks to Leigh Riffel from DBA stackxchange for the following code

UPDATE HOLIDAY_RESERVATION R SET SUBTOTAL = 
   NVL((SELECT F.FLI_PRICE FROM FLIGHT F WHERE F.FLI_ID = R.IN_FLIGHT_ID), 0) +
   NVL((SELECT F.FLI_PRICE FROM FLIGHT F WHERE F.FLI_ID = R.OUT_FLIGHT_ID), 0) +
   NVL((SELECT AC.ACC_PRICEPN FROM ACCOMMODATION AC WHERE AC.ACC_ID = R.ACC_ID), 0);

Now the subtotal is populated with the values obtained from the sum performed above >>

 RESV_ID     EMP_ID BOOKING_CUS_ID RESV_DATE HOLIDAY_S HOLIDAY_E IN_FLIGHT_ID OUT_FLIGHT_ID IN_FLIGHT_SEATS_NO OUT_FLIGHT_SEATS_NO     ACC_ID   SUBTOTAL
---------- ---------- -------------- --------- --------- --------- ------------ ------------- ------------------ ------------------- ---------- ----------
         1        338              1 16-FEB-12 18-MAR-12 20-APR-12            1            11                  2                   2          2       1405
         2        335              3 10-JAN-12 20-MAR-12 22-APR-12            2            12                  2                   2          4        553
         3        338              5 05-MAR-12 25-MAR-12 26-APR-12            3            13                  2                   2          6       1095
         4        328              7 02-JAN-12 25-MAR-12 25-APR-12            4            14                  2                   2          7       1443
         5        311              9 20-JAN-12 26-MAR-12 21-APR-12            5            15                  2                   2                   587
         6        317             11 07-JAN-12 27-MAR-12 22-APR-12            6            16                  2                   2                   920
         7        344             13 29-FEB-12 15-MAR-12 12-APR-12            7            17                  2                   2                   500
         8        326             15 11-JAN-12 18-MAR-12 12-APR-14            8            18                  2                   2                  1100
         9        329             17 16-JAN-12 19-MAR-12 17-APR-12                                                                   25        250
        10        323             19 18-FEB-12 20-MAR-12 21-APR-12                                                                   19        450

Subsequently the code was added to a trigger (which was the original intention)

CREATE OR REPLACE TRIGGER HR_SUBTOTAL
BEFORE INSERT OR UPDATE ON HOLIDAY_RESERVATION
FOR EACH ROW
BEGIN
   SELECT 
      NVL((SELECT F.Fli_Price FROM Flight F WHERE F.Fli_ID = :new.In_Flight_ID), 0) +
      NVL((SELECT F.Fli_Price FROM Flight F WHERE F.Fli_ID = :new.Out_Flight_ID), 0) +
      NVL((SELECT AC.Acc_PricePn FROM Accomodation AC WHERE AC.Acc_ID = :new.Acc_ID), 0)
      INTO :new.Subtotal
   FROM dual;
END;
/
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T21:07:15+00:00Added an answer on May 31, 2026 at 9:07 pm

    For the SUM, assuming you want to treat NULL values as 0, you’d just need to do an NVL on the numbers

    NVL( DEPART_FLIGHT_PRICE, 0 ) +
    NVL( RETURN_FLIGHT_PRICE, 0 ) +
    NVL( ACCOMMODATION_PRICE, 0 )
    

    As for the UPDATE, it sounds like you just need a correlated UPDATE statement.

    UPDATE reservation r
       SET subtotal = (SELECT (SELECT NVL( DEPART_FLIGHT_PRICE, 0 ) +
                              NVL( RETURN_FLIGHT_PRICE, 0 ) +
                              NVL( ACCOMMODATION_PRICE, 0 )
                         FROM (SELECT RESV_ID, 
                                      BOOKING_CUS_ID, 
                                      ACC_ID,
                                      (SELECT F.FLI_PRICE 
                                         FROM FLIGHT F 
                                        WHERE F.FLI_ID = R.IN_FLIGHT_ID) AS DEPART_FLIGHT_PRICE, 
                                      (SELECT F1.FLI_PRICE 
                                         FROM FLIGHT F1 
                                        WHERE F1.FLI_ID = R.OUT_FLIGHT_ID) AS RETURN_FLIGHT_PRICE, 
                                      (SELECT AC.ACC_PRICEPN 
                                         FROM ACCOMMODATION AC 
                                        WHERE AC.ACC_ID = R.ACC_ID) AS ACCOMMODATION_PRICE
                                 FROM dual));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Android I'm using the following statement: return bdd.rawQuery(SELECT * FROM + TABLE_EVENTS ,
I'm using the following SQL-Statement: SELECT Col1, count(*) as Col2, Col3 FROM table1 WHERE
I'm using the following statement SELECT TOP 5 rootcause, COUNT(IIF(accountability=Team 1,1,0)) FROM MOAQ WHERE
I am using the following statement: query_str='SELECT :NEW.FIRST_NAME||:NEW.LAST_NAME INTO HostID FROM INPUT_TABLE WHERE INPUT_ID='
I'm using the following SQL statement: SELECT reply.id, reply.content, author.username FROM thread, reply, author
Using the following SQLite statement: SELECT Customer, SUM(OrderAmount) AS TotalOrder FROM OrdersTable GROUP BY
I'm using the following SELECT statement: SELECT * FROM prefix_site_tmplvars LEFT JOIN prefix_site_tmplvar_contentvalues ON
I have a problem creating the following SQL Statement using LINQ & C# select
I have the following prepared statement: $sql = PREPARE stmt_name FROM 'SELECT I.item_id, I.name
Taking the following statement: select count( 1 ) as cnt from tbl where val=

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.