Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我遇到了一个我无法解决的问题。我有一个包含以下列的表格: Personid, type.
Personid
type
每个可以有几行personid 我想要的结果将是每个人有多少行类型 5,12,71 的聚合。
personid
所以表格将如下所示:
Personid type 5 type 12 type 71 11 0 2 7 15 1 6 0
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