小弟现在有一个疑惑,就是关于rollup汇总的问题我的SQL如下。
select comp_code,sum(to_number(FDI_DATA)) as FDI_DATA from tbdimendata where comp_code in (select dimvalue_code from tbdimenhiervalue start with dimvalue_parentcode='D110005' connect by prior dimvalue_code = dimvalue_parentcode) group by rollup(comp_code) (select dimvalue_code from tbdimenhiervalue start with dimvalue_parentcode='D110005' connect by prior dimvalue_code = dimvalue_parentcode)返回('D001','D002'),
rollup按这两个单位进行汇总,但是,rollup是先汇('D001','D002'),再汇('D001'),再汇('D002')这样能没有什么方法能让我只汇('D001','D002')的结果集,而不再汇('D001'),('D002')这两个单位,请指教!
select comp_code,sum(to_number(FDI_DATA)) as FDI_DATA from tbdimendata where comp_code in (select dimvalue_code from tbdimenhiervalue start with dimvalue_parentcode='D110005' connect by prior dimvalue_code = dimvalue_parentcode) group by rollup(comp_code) (select dimvalue_code from tbdimenhiervalue start with dimvalue_parentcode='D110005' connect by prior dimvalue_code = dimvalue_parentcode)返回('D001','D002'),
rollup按这两个单位进行汇总,但是,rollup是先汇('D001','D002'),再汇('D001'),再汇('D002')这样能没有什么方法能让我只汇('D001','D002')的结果集,而不再汇('D001'),('D002')这两个单位,请指教!
select comp_code,sum(to_number(FDI_DATA)) as FDI_DATA from tbdimendata where comp_code in (select dimvalue_code from tbdimenhiervalue start with dimvalue_parentcode='D110005' connect by prior dimvalue_code = dimvalue_parentcode)
不就可以么
select colname,sum(colname2) from tab_name
group by colname 但是如果需要分组的统计结果和总的统计结果,可以通过union all(union)得到
select colname, sum(colname2) from tab_name
group by colname
union all /union
select colname, sum(colname2) from tab_name
或者使用分析函数得到
select colname, sum(colname2) from tab_name
group by rollup(colname)
rollup的目的是实现多层次的汇总而楼主已经明确说明不需要多层次的汇总,只需要最终的汇总结果,那么不清楚楼主为什么需要rollup;也不清楚楼主完整的需求是什么
能看见的就是楼主在问:rollup有没有去掉中间层次汇总结果的语句或者语法格式
能回答的只有:没有
1
2 (下面有2-1,2-2)
3
4 (下面有4-1且4-1下有4-1-1 子节点)
现在节点1,2,4,4-1都没有数,需要将4-1-1汇到4-1再将4-1汇到4,这样4和4-1就有数了。2和1也都是同理。
但是我发现比如我汇时按根为1向下汇时,会出现一些多余的数据这给我接下来的操作带来很多不便,所以我想在再对他进行筛选.