oracle通过分组复杂,谁能给个例子有case(when ....) group by where and 这种组合起来比较复杂的分组...

select *

from (select case

when grouping(fs_batchno) = 0 and grouping(fs_steeltype) = 0 and

grouping(fs_spec) = 0 then

0

when grouping(fs_batchno) = 1 and grouping(fs_steeltype) = 1 and

grouping(fs_spec) = 0 then

1

when grouping(fs_batchno) = 1 and grouping(fs_steeltype) = 0 and

grouping(fs_spec) = 1 then

2

when grouping(fs_batchno) = 1 and grouping(fs_steeltype) = 1 and

grouping(fs_spec) = 1 then

3

else

4

end XH,

case

when grouping(fs_batchno) = 1 and grouping(fs_steeltype) = 1 and

grouping(fs_spec) = 0 then

'规格【' || fs_spec || '】小计:'

when grouping(fs_batchno) = 1 and grouping(fs_steeltype) = 0 and

grouping(fs_spec) = 1 then

'牌号【' || fs_steeltype || '】小计:'

when grouping(fs_batchno) = 1 and grouping(fs_steeltype) = 1 and

grouping(fs_spec) = 1 then

'总计:'

when grouping(fs_steeltype) = 0 and grouping(fs_spec) = 0 then

max(fs_batchno)

end fs_batchno,

case

when grouping(fs_batchno) = 0 and grouping(fs_steeltype) = 0 and

grouping(fs_spec) = 0 then

fs_steeltype

else

null

end fs_steeltype,

case

when grouping(fs_batchno) = 0 and grouping(fs_steeltype) = 0 and

grouping(fs_spec) = 0 then

fs_spec

else

null

end fs_spec,

sum(nvl(fn_bandcount, 0)) fn_bandcount,

sum(nvl(fn_totalweight, 0)) fn_totalweight,

case

when grouping(fs_batchno) = 0 and grouping(fs_steeltype) = 0 and

grouping(fs_spec) = 0 then

max(fs_productno)

else

null

end fs_productno,

case

when grouping(fs_batchno) = 0 and grouping(fs_steeltype) = 0 and

grouping(fs_spec) = 0 then

max(fd_starttime)

else

null

end fd_starttime,

case

when grouping(fs_batchno) = 0 and grouping(fs_steeltype) = 0 and

grouping(fs_spec) = 0 then

max(fd_endtime)

else

null

end fd_endtime,

case

when grouping(fs_batchno) = 0 and grouping(fs_steeltype) = 0 and

grouping(fs_spec) = 0 then

max(fs_completeflag)

else

null

end fs_completeflag

from (select t.fs_batchno,

t.fs_productno,

t.fs_steeltype,

t.fs_spec,

t.fn_bandcount,

t.fn_totalweight,

to_char(t.fd_starttime, 'yyyy-MM-dd hh24:mi:ss') fd_starttime,

to_char(t.fd_endtime, 'yyyy-MM-dd hh24:mi:ss') fd_endtime,

decode(t.fs_completeflag, '1', '√', '') fs_completeflag

from dt_gx_storageweightmain t

where 1 = 1

and t.fd_starttime between

to_date('2012-04-01 00:00', 'yyyy-MM-dd HH24:mi') and

to_date('2012-04-09 23:59', 'yyyy-MM-dd HH24:mi'))

group by cube(fs_batchno, fs_steeltype, fs_spec))

where xh <> 4

order by xh, fs_batchno

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值