我们有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}}
答案 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;