Skip to content
Advertisement

How to use sql different where statement on the basis of column’s value?

I have table named offers.It has following columns

  1. is_special having value true or false
  2. normal_expiry_date having a date value
  3. special_expiry_date having a date value

Now if row has is_special = false then I want to use where normal_expiry_date > current_date,if is_special = true then where special_expiry_date > current_date

Thanks a lot to you even if you tried to help

Advertisement

Answer

One option would be

where current_date < case when is_special = false then normal_expiry_date
                          when is_special = true  then special_expiry_date
                     end
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement