hi guys i have a table like this
and I basically am trying to select the cheapest price from price_band_1, price_band_2, price_band_3, price_band_4, price_band_5 and then I want to select the corresponding month and dates.
I can select the cheapest price like this
but I'm really confused as to how to select the corresponding month & dates?
this surely cant just be a case of attaching another union select statement to select the month & date columns. I'm guessing it needs some sort of If statement attached?
IF MINPRICE = PRICEBAND 1
DO
Select MONTH_Band_1, DATE_Band_1??
any ideas?
thanks in advance
Omar.
Code:
ID | Flight_Route | Price_Band_1 | Month_Band_1 | Date_Band_1 | Price_Band_2 | Month_Band_2 | Date_Band_2 | Price_Band_3 | Month_Band_3 | Date_Band_4 | Price_Band_4 | Month_Band_4 | Date_Band_4 1 TEST1 99 MAY 12, 19, 31 199 JUNE 12, 19, 31 199 JULY 12, 19, 31 199 AUG 12, 19, 31
I can select the cheapest price like this
Code:
Select CheapestPrice = MIN(CheapestPrice) from & _ (Select MIN(Price_Band_1) As CheapestPrice from mytablename where Id = 1 & _ UNION ALL & _ Select MIN(Price_Band_2) from mytablename where Id = 1 & _ UNION ALL & _ Select MIN(Price_Band_3) from mytablename where Id = 1 & _ UNION ALL & _ Select MIN(Price_Band_4) from mytablename where Id = 1 & _ UNION ALL & _ Select MIN(Price_Band_5) from mytablename where Id = 1 )x
this surely cant just be a case of attaching another union select statement to select the month & date columns. I'm guessing it needs some sort of If statement attached?
IF MINPRICE = PRICEBAND 1
DO
Select MONTH_Band_1, DATE_Band_1??
any ideas?
thanks in advance
Omar.
Comment