DISTINCT AND COUNT

时间:2013-09-17 07:47:58

标签: sql

有一列国家代码和另外3列有MEDALS GOLD,SILVER和BRONZE 我想展示他们为每个国家获得的金牌,银牌和铜牌的总数,

图表看起来像这样

COUNTRY_ISOCODE  PART_GOLD PART_SILVER PART_BRONZE
--------------- ---------- ----------- -----------
AUS                      2           0           0 
AUS                      2           0           3 
AUS                      0           0           0 
ZAF                      0           0           0 
ZAF                      1           1           0

但我希望它像这样

COUNTRY_ISOCODE  PART_GOLD PART_SILVER PART_BRONZE
--------------- ---------- ----------- -----------
AUS                      4           0           0 
ZAF                      1           1           0

1 个答案:

答案 0 :(得分:3)

假设您谈论SQL(如countdistinct所暗示的那样):

select country_isocode, 
       sum(part_gold) as part_gold, 
       sum(part_silver) as part_silver,
       sum(part_bronze) as part_bronze
from the_table
group by country_isocode;