如何在oracle10g中拆分多列中的列数据?

时间:2016-03-31 11:07:34

标签: sql oracle oracle10g

我们有3列METRIC,count,SETS和Data的表格如下:

    "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

我想通过“SET1”和“SET2”分割数据。我应该采取什么方法 使用?我想要的结果是:

{{1}}

1 个答案:

答案 0 :(得分:3)

您正在寻找过滤后的聚合:

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;