我在旧版数据库中有两个字段。我想查询其中的一个,但经常查询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'
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句