group by field1,field2
显示结果为
1,1,2
2,1,2
2,2,2
3,3,2
但我想要显示结果要这样地
1,1,2
1,2,0
1,3,0
2,1,2
2,2,2
2,3,0
3,1,0
3,2,0
3,3,2
也就是第一个分组项中必须有第二个分组项所以有项目,为了组二维的图表分析,一个语句能实现吗?
如果第一个分组项中没有第二个分组项,就补"0"
显示结果为
1,1,2
2,1,2
2,2,2
3,3,2
但我想要显示结果要这样地
1,1,2
1,2,0
1,3,0
2,1,2
2,2,2
2,3,0
3,1,0
3,2,0
3,3,2
也就是第一个分组项中必须有第二个分组项所以有项目,为了组二维的图表分析,一个语句能实现吗?
如果第一个分组项中没有第二个分组项,就补"0"
select field1,field2,(select nvl(max(field3),0) from (select ... from .. group by filed1,field2) t
where t.field1=a.field1 and t.field2=b.field2) field3 from
(select distinct field1 from tbname) a,
(select distinct field2 from tbname) b;
select field1, field2, sum(field3)
from (select * from t
union all
select field1, field2, field3
from (select distinct field1 from t) t1,
(select distinct field2, 0 field3 from t) t2
)
group by field1, field2
如果再整不出来,就用界面上处理了,汗!!
a.field1,
b.field2,
(select nvl(count(*),0) from tabname where field1=a.field1 and field2=b.field2) as field3
from
(select distinct field1 from tabname) a,
(select distinct field2 from tabname) b
order by
a.field1,b.field2
/////////////
哈哈,老湘,我第一次来这里发贴就碰到你,哈哈,汗!!!!