oracle - SQL of group by in order by -


[raw data]  b    c  1  10   1  1  10   2 2  20   3 2  20   4 1  100  5 1  100  6  [wanted result]    sum_of_b 1    20 2    40 1    200 

it's unuseful query has simple 'group by' clause , 'dense_rank on partition by' because grouping works rows. want grouping in state of ordering. how write proper query?

you need identify groups of adjacent records. can using difference of row numbers approach -- assuming c orders rows. difference constant consecutive values of a same:

select a, sum(b) (select t.*,              (row_number() on (order c) -               row_number() on (partition order c)              ) grp       table t      ) t group grp, order min(c); 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -