Mysql 按 3 个字段分组

Mysql Group by 3 fields with count

查看附件图片以了解我的数据。

我想得到这样的结果:

SessionNumber | Event Date| Critical Care Count | Pulmonary Circulation
G1            | 5/19/2018 | 2                   | 3
G1            | 5/20/2018 | 5                   | 1
PCC1          | 5/19/2018 | 4                   | 5

我正在尝试计算每个 SessionNumber 和 EventDate 的各种 primaryAssembly、主题、reg。

这是我正在使用的查询:

select SessionNumber, EventDate, count(distinct BadgeID) as CriticalCareCount 
from beacon 
where primaryAssembly="Critical Care" 
group by SessionNumber, EventDate 
order by EventDate;

但我宁愿不必使用 'Where' 子句。我想对术语本身进行分组。 这是一个屏幕截图:

数据透视查询可以提供帮助:

SELECT SessionNumber,Event_Date,
       count( case when primaryAssembly = 'Critical Care' then 1 end ) 
                   As Critical_Care_Count,
       count( case when primaryAssembly = 'Pulmonary Circulation' then 1 end ) 
                   As Pulmonary_Circulation_Count,
       count( case when primaryAssembly = 'Some other value' then 1 end ) 
                   As Some_other_value_Count,
       ......
       ......
       count( case when some_other_logical_condition then 1 end ) 
                   As some_other_condition_count
       ......
       ......
       SUM( case when primaryAssembly = 'Critical Care' then Duration else 0 end ) 
                   As sum_of_duration_for_critical_care
       ......
       ......
       count(*) As total_count
FROM table
GROUP BY SessionNumber,Event_Date