标签: precedence

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

我有一个"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
查看次数

为什么此查询返回的用户不是在提供的日期出生?

我正在尝试使用姓名和出生日期搜索客户。我的查询包含在下面。

Select * 
From Client
Inner Join Address
On Client.num = Address.cl_num
Where 
   Client.fname LIKE ‘%john%’ and Client.sname LIKE ‘%doe%’
Or
    Client.fname LIKE ‘%doe%’ and Client.sname LIKE ‘%john%’
And Client.year = 1973
And Client.month = 06
And Client.day = 05
Run Code Online (Sandbox Code Playgroud)

然而,结果显示的客户不是那天出生的。我的说法有问题吗?

该查询在 iSeries 服务器上运行。

precedence

2
推荐指数
1
解决办法
37
查看次数

标签 统计

precedence ×2

postgresql ×1

query ×1