sql - How to use rollup function in oracle -


i trying use group rollup oracle function, not getting right.

here data format (l1_proj_id level 1 project id etc.....)

proj_id  hours_charged l1_proj_id  l2_proj_id l3_proj_id     l4_proj_id   -------------------------------------------------------------------------   1100.10         20       1100        1100.10    null           null   1100.11.01      30       1100        1100.11    1100.11.01     null   1100.11.02      40       1100        1100.11    1100.11.02     null   1100.12.01.01   50       1100        1100.12    1100.12.01     1100.12.01.01   

i need roll totals , output should

proj_level  hours_charged   --------------------------   1100            140   1100.10          20   1100.11          70   1100.11.01       30   1100.11.02       40    1100.12          50    1100.12.01       50   1100.12.01.01    50   

please, let me know if there other easy way do.

as of can data like...

select    l1_proj_id,    sum(hours_charged) hours_charged  table   group    l1_proj_id  union    select    l2_proj_id,    sum(hours_charged) hours_charged  table  group    21_proj_id   union   select    l3_proj_id,    sum(hours_charged) hours_charged  table  group    l3_proj_id   union   select    l4_proj_id,    sum(hours_charged) hours_charged  table  group    l4_proj_id 

this not use rollup, think might deliver results. in essence, unnest columns rows. should relatively easy scale if content changes.

with levels (   select level id   dual   connect level <= 4 ), all_data (   select     case l.id       when 1 l1_proj_id       when 2 l2_proj_id       when 3 l3_proj_id       when 4 l4_proj_id     end project_id,     t.hours_charged       table t,     levels l ) select   project_id, sum (hours_charged) hours_charged all_data project_id not null group project_id 

Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -