php - define variable using conditional statement in MySQL -
I have a table "product" with columns:
| Price | Discount_pris | Start_disk | End_discount | ... |
* start_discount and end_discount are a unix timestamp
The current price of the product depends on the time - if ' time () ' ' start_discount ' and ' end_discount ' then current value is' discount_price ', otherwise' Price '
I'm trying to return the " current_price " variable. In PHP, I will just write:
$ current_price = (time)> $ start_discount & time ()
How can I get the top of MySQL without including PHP?
I still have this:
SELECT *, (** price or discount_price **) as current products, where active, active = 1 and current_prins Ordering '100' and '200' between current_pres;
There is a way to do that, I'm just selecting the value that You can choose whatever you want from the table
select the case when now ()> Start_discount and now () & lt; End_discount Then edit the current_price as discount_price other price end WHERE active = 1 and between price '100' and '200' current current_price
Edit: Just see that you Where current_price is in condition, which you can not do since its aliases, so you may have to use a table column in the section where or
ones
section
now ()> Start_discount and now () & lt; And_ Discount then discounts_pricks from other price and products with current_price containing WHERE active = 1 as current_price, '100' and '200' ORDER BY current_price
here is a test I
mysql> Table products (value int, discount_print int, start_discount date, end date); The query is ok, affected 0 rows (0.08 seconds) mysql & gt; Insert the value of the products (100, 60, '2014-10-01', '2014-11-01'), (200,160, '2014-10-01', '2014-10-10'), (300,200 , '2014-11-01', '2014-11-15'); The query is correct, affected 3 rows (0.00 seconds) Records: 3 duplicates: 0 warnings: 0 mysql & gt; Select the case when Now ()> Start_discount and now () & lt; End_discount then current_price discount_price other price end as current_price by order of products; + --------------- + | Current_price | + --------------- + | 60 | | 200 | | 300 + --------------- + 3 lines set (0.00 seconds)
Comments
Post a Comment