I have a table "products" with columns like:
| price | discount_price | start_discount | end_discount | ... |
*start_discount and end_discount is a UNIX timestamp
Current price of a product depends on time - if 'time()' is between 'start_discount' and 'end_discount' then the current price is 'discount_price', otherwise is 'price'
I am trying to return "current_price" variable. In PHP, I would just write:
$current_price = (time() > $start_discount && time() < $end_discount)? $discount_price : $price;
How can I achieve the same as above in MySQL without involving PHP?
I have this so far:
SELECT *, (**price OR discount_price**) as current_price FROM products WHERE active = 1 AND current_price BETWEEN '100' AND '200' ORDER BY current_price;