Oracle: select a.f1, nvl(ct,0) from ( select f1,count(*) ct from table1 where f2=xxx ) a, ( select distinct f1 from table1 ) b where a.f1(+)=b.f1; 如果有另外的表存储所有的f1,可用它代替子查询b
to MountLion: 直接用nvl就可以了,为什么要那么复杂? It's my sql: select f1,nvl(count(*),0) from table1 where f2 = xxx group by f1
select a.f1, nvl(ct,0)
from
(
select f1,count(*) ct from table1 where f2=xxx
) a,
(
select distinct f1 from table1
) b
where a.f1(+)=b.f1;
如果有另外的表存储所有的f1,可用它代替子查询b
直接用nvl就可以了,为什么要那么复杂?
It's my sql:
select f1,nvl(count(*),0)
from table1
where f2 = xxx
group by f1