在Apache中的where条件点燃SQL中处理空值args

时间:2018-06-26 06:02:54

标签: sql ignite

我不知道如何为以下查询命中索引:

select * from Cache 
where accountId = 'demo' 
and (? is null or country = ?) 
and (? is null or county = ?) 
and (? is null or province = ?) 
and (? is null or city = ?) 
and (? is null or locality = ?) 
order by createdAt desc

我在cols上有一个orderedGroup索引(accountId,国家/地区,国家/地区,省,城市,地区,createdAt(desc))。如果我删除了isull,它正在工作。也许有另一种方法可以在sql中重写它,以便能够解决空参数?

1 个答案:

答案 0 :(得分:1)

您可以使用OR expansion重写它:

select * from Cache 
where accountId = 'demo' and ? is null
union all
select * from Cache 
where accountId = 'demo' and city = ?