小编sec*_*ast的帖子

如果过滤列有值,则查询结果优先

我有一个"customer_config"包含这些列的表:

company (varchar)
warehouse (numeric)
section (numeric)
config_keyword (varchar)
config_value (varchar)
Run Code Online (Sandbox Code Playgroud)

这两config_*列可以应用于整个公司(warehousesection为空)、公司内的整个仓库(section为空)或仓库内的一个部分。

因此,我们可以为公司设置一个默认行,然后使用一个或多个行来覆盖特定仓库或仓库和部分的配置值。

我只想返回给定公司、仓库和部门的最具体的行。像这样的伪代码:

results = select * from customer_config where (all match)
if results empty
    results = select * from customer_config where (company_code and warehouse match)
if results empty
    results = select * from customer_config where (company_code matches)
Run Code Online (Sandbox Code Playgroud)

最具体的行应优先。

更新

同一级别上可以有多个相同的条目config_keyword
是否也可以为单个关键字返回多行?

postgresql query precedence

3
推荐指数
1
解决办法
874
查看次数

标签 统计

postgresql ×1

precedence ×1

query ×1