我在旧数据库中有两个字段。我想查询其中之一,但它经常null
,在这种情况下,是否有像if
语句like Where if field_a !== null { field_a='Value' } else { field_b='Value' }
我的问题是,有没有办法在 sql 本身中做到这一点,或者我必须执行两个查询,一个用于检查是否为 null,然后在我的逻辑中检查一个 if 语句?
我认为您可以捕获这样的逻辑:
where field_a = 'Value' or (field_a is NULL and field_b = 'Value')
或者更简单地说:
where field_a = 'Value' or field_b = 'Value'