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 :

enter image description here

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

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -