0

私は解決できなかった問題を抱えています。次の列を持つテーブルがあります: Personid, type.

それぞれに複数の行が存在する可能性があります。personid 望ましい結果は、各人が持っているタイプ 5、12、71 の行数の集計です。

したがって、テーブルは次のようになります。

  Personid  type 5  type 12  type 71

   11          0       2        7
   15          1       6        0
4

1 に答える 1

2
select
  personid,
  count(case when type = 5 then 1 end) type5cnt,
  count(case when type = 12 then 12 end) type12cnt,
  count(case when type = 71 then 71 end) type71cnt
from table_name
group by personid
于 2012-12-19T08:28:45.170 に答える