Shubh
Shubh

Reputation: 17

how to split a data of column in more than one column in oracle10g?

We have table with 3 columns METRIC,count,SETS and Data looks like:

            "METRIC"           "COUNT" "SETS"           
            FOR_PEOPLE_LIKE_ME      0   SET1
            FOR_YOUNG_PEOPLE        1   SET1
            GOOD_TASTE              0   SET1
            HIGH_SATISFACTION       2   SET1
            FOR_STATUS_ORIENTED     0   SET1

            FOR_PEOPLE_LIKE_ME      0   SET2
            FOR_YOUNG_PEOPLE        1   SET2
            GOOD_TASTE              0   SET2
            HIGH_SATISFACTION       0   SET2
            FOR_STATUS_ORIENTED     3   SET2

I want to split the data by "SET1" and "SET2".What approach should I use? My desired result is:

    "METRIC"             "SET1"   "SET2"
    FOR_PEOPLE_LIKE_ME      0         0    
    FOR_YOUNG_PEOPLE        1         1
    GOOD_TASTE              0         0    
    HIGH_SATISFACTION       2         0
    FOR_STATUS_ORIENTED     0         3

Upvotes: 0

Views: 39

Answers (1)

user330315
user330315

Reputation:

You are looking for a filtered aggregate:

select metric, 
       sum(case sets when 'SET1' then "COUNT" end) as SET1,
       sum(case sets when 'SET2' then "COUNT" end) as SET2
from the_table
group by metric;

Upvotes: 3

Related Questions