我认为一旦CASE找到匹配项,就会中断并返回第一个匹配项。但是,我得到所有匹配的案件陈述。例如Oracle多个CASE语句评估为true
select distinct PERSON,
LOCATION,
(case
when LOCATION = 'CA' and PHONE is not null
then PHONE
when LOCATION = 'NY' and PHONE is not null
then PHONE
when LOCATION = 'FL' and PHONE is not null
then PHONE
when LOCATION = 'MA' and PHONE is not null
then PHONE
else '---'
end)
from DIRECTORY
where LOCATION in
('CA', 'NY', 'FL', 'MA');
因为人可以在每个国家的电话号码,我要的是发现,基本上是“排名”由各州的顺序第一电话号码。我得到的是所有找到的电话号码。
THX ...
谢谢 - 这是我失踪的第二个cte。试图从第一个cte中拉出像max(LOCATION_RANK)这样的东西,但仍然返回了所有行。这太好了 - 非常感谢... – user1628169