Mysql: How to query with if else condition inside if -
i'm getting trouble query data. not know start query if else condition inside if.
problem is: how query if type = cpm , end_date < now() change result value type before, , if type = cpm , end_date > now() change result value type after. have data in table, result below :
and want result below :
array( [0] => array ( [id] => 1 [type] => free [end_date] => 2013-06-20 ) [1] => array ( [id] => 4 [type] => after [end_date] => 2013-08-29 ) [2] => array ( [id] => 5 [type] => before [end_date] => 2013-06-20 ) )
thanks in advance.
something should work:
select id, case when (type = 'cpm' , end_date < now()) 'before' when (type = 'cpm' , end_date > now()) 'after' else type end type, end_date my_table;
Comments
Post a Comment