Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

SQL calculate total after unpivot

vijzMay 4 2018 — edited May 4 2018

Below is demo table:

select value

from

(

    (

        select

            1 v1,

            2 v2,

            3 v3,

            4 v4,

            5 v5

        from dual

    )

    unpivot

    (

        value

        for value_type in

            (v1,v2,v3,v4,v5)

    )

)

output:

     VALUE

----------

         1

         2

         3

         4

And We are looking for Total at the end something like below, to calculate total at the end result:

VALUE

----------

         1

         2

         3

         4

         5

----------

sum=15

select value

from

(

    (

        select

            1 v1,

            2 v2,

            3 v3,

            4 v4,

            5 v5

        from dual

    )

    unpivot

    (

        value

        for value_type in

            (v1,v2,v3,v4,v5)

    )

) group by rollup(value)  -- rollup is not possible as its not a group by

This post has been answered by Paulzip on May 4 2018
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 1 2018
Added on May 4 2018
9 comments
457 views