Google 工作表:带有数据透视子句的简单查询

Google Sheets : simple query with pivot clause

我找不到一种方法来简化查询以获得与数据透视表类似的结果。 虽然数据透视 table 很简单,但我更愿意使用查询,因为这样我就可以个性化 headers.

这是 link 的数据:

https://docs.google.com/spreadsheets/d/1R461nv2lD4efpuUuDonFMYGnLH510n7gwpbzG2WAUaw/edit?usp=sharing.

这是有效的嵌入式查询:

= query(query(Data!A1:C, " SELECT B,count(B) WHERE B is not null GROUP BY B,C ORDER BY B ASC "), "SELECT Col1, Count(Col1) group by Col1 LABEL Col1 'Status',Count(Col1) 'Count'",1 )

这是我想与数据透视子句一起使用的查询:

=query(Data!A1:C, "Select B, count(C) group by count(C)  Pivot C" ,1)

这是我要找的东西:

如果你想旋转 C 列,它应该是:

=QUERY({Data!A1:C, Data!C1:C}, 
 "select Col2,count(Col3) where Col1 is not null group by Col2 pivot Col4", 1)

尝试

={"Status","Count(Categories)";transpose(query(unique(B:C),"select count(Col2) where Col2 is not null pivot Col1",1))}

或更简单

=query(unique(B:C),"select Col1, count(Col2) where Col2 is not null group by Col1",1)