我需要从第一个匹配条件获取结果,如果在该级别找到结果,则从那里返回或转到下一个级别 找到结果。
任何帮助表示赞赏。
最佳答案
这是一个优先级查询(有联系)。一种方法使用dense_rank()
:
select rsc.*
from (select rsc.*,
dense_rank() over (order by case when rsc.entityId = :accountId and rsc.entityTypeCode = 'A' then 1
when rsc.entityId = :companyId and rsc.entityTypeCode = 'C' then 2
when rsc.entityId = :issuerId and rsc.entityTypeCode = 'I' then 3
else 4
end) as seqnum
from CurrentRuleSetContents rsc
where (rsc.entityId = :accountId and rsc.entityTypeCode = 'A') or
(rsc.entityId = :companyId and rsc.entityTypeCode = 'C') or
(rsc.entityId = :issuerId and rsc.entityTypeCode = 'I') or
(rsc.industryCode = :industryCode)
) rsc
where seqnum = 1;
关于mysql - 获取第一个匹配条件的结果,不考虑下一个匹配条件的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52895824/