如果我理解的很好,这可能是一种方法。 假设你已经拥有你[R查询得到的结果,你可以用这种方式:
with yourResult(server_id, server_name, explicit_perm, rank, total) as (
select 93, 'AVIZNER', 1, 1, 10 from dual union all
select 93, 'AVIZNER', 0, 6, 10 from dual union all
select 11, 'XXXXXXX', 1, 1, 10 from dual union all
select 22, 'YYYYYYY', 0, 1, 10 from dual union all
select 11, 'ZZZZZZZ', 1, 1, 11 from dual union all
select 11, 'ZZZZZZZ', 1, 2, 22 from dual union all
select 11, 'ZZZZZZZ', 0, 1, 10 from dual
)
select server_id, server_name, explicit_perm, rank, total
from (
select server_id, server_name, explicit_perm, rank, total,
count (case when explicit_perm = 1 then 1 end) over (partition by server_id) as count_perm_1
from yourResult
)
where not (explicit_perm = 0 and count_perm_1 > 0)
这种计算行数与explicit_perm = 1
为每server_id
,然后排除所有explicit_perm = 0
和至少一行行与explicit_perm = 1
存在相同的server_id
。
与我的样本数据,结果:
SERVER_ID SERVER_ EXPLICIT_PERM RANK TOTAL
---------- ------- ------------- ---------- ----------
11 ZZZZZZZ 1 2 22
11 ZZZZZZZ 1 1 11
11 XXXXXXX 1 1 10
22 YYYYYYY 0 1 10
93 AVIZNER 1 1 10
如何简单地使用外侧的位置,我的意思是脱离了union的括号? –
我需要放弃EXPLICIT_PERM = 0的行,只有在服务器ID出现两次的情况下,我该如何检测? –
为什么你想用PL/SQL(一种编程语言)而不是SQL来解决这个问题? –