mysql - Join two SQL Queries based on first query answer -


i have been looking everywhere , best website ask help. have make sql query checks total amount of bookings specific flight , based on number of bookings system should provide choice of aircraft. first query works , finds total number of bookings , think have case statement right choose aircraft cant find way of physically joining both queries , tried use unison , inner join , nested queries appears total number of seats booked (the answer first query ) cannot found please me guys.

first sql query(find total number of bookings )

select count(bookingdetails.flightid)as totalnumberofseatsbooked,flightdetails.flightid  bookingdetails, bookingdetails temp,flightdetails bookingdetails.bookingid = temp.bookingid , bookingdetails.flightid= flightdetails.flightid group flightid; 

second sql query(choose aircraft type depending on how many bookings made)

    select case chooseaircraft     when totalnumberofseatsbooked <= 110 'ba 146-200'     else'embraer 170'     end choiceofaircraft     aircrafttype; 

big after 1 answer think im heading in right direction merging both queries , code displays total number of seats , flight number in sub query choice of aircraft column still doesnt show if run query self know close getting , appreciate become better in sql code have :

select count(bookingdetails.flightid)as totalnumberofseatsbooked,flightdetails.flightid  bookingdetails, bookingdetails temp,flightdetails  bookingdetails.bookingid = temp.bookingid , bookingdetails.flightid= flightdetails.flightid , bookingdetails.flightid= flightdetails.flightid in( select case when count(bookingdetails.flightid) <= 110 'ba 146-200' else'embraer 170'  end choiceofaircraft bookingdetails,flightdetails) group flightid; 

you can use same expression count(bookingdetails.flightid) in case statement (or) wrap first query in subquery , access column in outer query. is

case when count(bookingdetails.flightid) <= 110 'ba 146-200' else'embraer 170' end choiceofaircraft 

Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -