I wrote a sql query to get max and min price for each ticket type, like below
select A.ticket_type,C.min_price, B.max_price from ticket as A inner join (select ticket_type, max(original_price) as max_price from ticket group by ticket_type) B inner join (select ticket_type, min(original_price) as min_price from ticket group by ticket_type) C on A.ticket_type=B.ticket_type AND B.ticket_type=C.ticket_type AND A.original_price=B.max_price
Now, I need to add discount_price, discount_from and discount_to to this query. which means if today is between discount_from and discount_to, the price will get discount_price, otherwise will get the original_price, then the final result will print the max and min price of each ticket type. How to add this if statement in? Anyone can help me with this?
Thank you
Aucun commentaire:
Enregistrer un commentaire