Mysql query with if exists check in where clause
I have two tables (A and B) where my query compares a calculation from
table A with a range in table B and then insert a corresponding value to
the range(also in table B) in the third table(table C) based on dates.
However,it is a possibility that table A may not have data for everyday
and for those days i want to enter the value against the second lowest
range.
I am looking for a way to embed IF EXISTS in the WHERE clause something
like this:
SELECT B.value from TableB B INNER JOIN TableA A ON A.id=B.id WHERE B.id=4
and (IF DATA EXISTS) B.v1+B.v2 between A.min and A.max (ELSE Choose the
second lowest A.min)
The query above is an example to explain what i am trying to do, hence, it
is not a valid query. I do not want to use a subquery for obvious
performance issues.
I will appreciate any help.Thanks in advance :)
No comments:
Post a Comment