I want to simplify the below sql code without change the business logic.here I mentioned postgresql code that I want to modify.
SELECT IF(
(SELECT `rate` FROM `vat_rate` WHERE '2017-05-12' BETWEEN from_date AND to_date) is not null ,
(SELECT `rate` FROM `vat_rate` WHERE '2017-05-12' BETWEEN from_date AND to_date) ,
IF((SELECT `rate` FROM `vat_rate` WHERE from_date is null and '2017-05-12' < to_date ) is not null,
(SELECT `rate` FROM `vat_rate` WHERE from_date is null and '2017-05-12' < to_date ),
IF(
(SELECT `rate` FROM `vat_rate` WHERE to_date is null and '2017-05-12' > from_date) is not null,
(SELECT `rate` FROM `vat_rate` WHERE to_date is null and '2017-05-12' > from_date),
'not found'
)
)
) as rate
ifstatement. And backticks are also illegal for SQL identifiers. Please edit your question and explain the actual problem you are trying to solve (instead of throwing a bunch of invalid SQL at us) and add some sample data and the expected output based on that data. Formatted text please, no screen shots