3,499
社区成员
发帖
与我相关
我的任务
分享
Select Distinct n,
Count(m) Over(Partition By n),
(Count(m)
Over(Partition By n) -
(Select Count(m) Over(Partition By n)
From a
Where Not Exists (Select 1 From b Where b.j = a.m)))
From a
create table t1
(
m int,
n varchar2(20)
)
;
create table t2
(
j int,
k varchar2(10)
);
insert into t1 select 131,'q' from dual
union all
select 132,'w' from dual union all
select 135,'e' from dual union all
select 132,'e' from dual;
commit;
insert into t2 select 131,'tt' from dual
union all
select 132,'mm' from dual
commit;
--SQL语句
select k.n,k.cnt1, nvl(k1.cnt2,0) as cnt2
from (select distinct n, count(*) over(partition by n order by n) as cnt1 from t1) k,
(select distinct n, count(*) over(partition by n order by n) as cnt2
from t1
where t1.m not in (select j from t2)) k1
where k.n = k1.n(+)