我有一个REST端点是这样的:选择列名其中列名= all_values
www.icecreamstore.com/stock?brand=hershey&flavour=vanilla
现在,
两个brand
和flavour
是可选的。
所以下面也是完全有效的:
www.icecreamstore.com/stock?flavour=vanilla
www.icecreamstore.com/stock?brand=hershey
www.icecreamstore.com/stock
这些API映射到SQL查询:
select count(*) from stock where brand=? and flavour=?
是否可以使用单个查询,而不是为每个请求参数组合编写单独的查询。
另外,
是否有可能写出这样的查询:
select count(*) from stock where brand=* and flavour=*
注:我与LIKE
在没有请求参数的情况下,使用column_name LIKE '%%'
目前管理。但是,如果列不存储字符串类型的值。
您正在使用哪些DBMS? Postgres的?甲骨文? –
我正在使用postgres –