如果条件为真,我只希望执行'和'条件。如果为false,则应忽略“和”条件。
select *
from table1 t1
left join table2 t2 on t1.a = t2.a
where t2.a = 'some value'
and t2.b = 'some value' --execute only if f.e. t1.c = 'some value'
答案 0 :(得分:1)
你可以试试这个:
SELECT *
FROM table1 AS t1
LEFT JOIN table2 t2 ON t1.a = t2.a
WHERE t2.a = 'some value'
AND ((t2.b = 'some value' AND t1.c = 'some value') OR t1.c <> 'some value')