我有一张表如下 OPERATIONS
OPERATOR-OPERATION TYPE
Ahmet DELETE
Ahmet UPDATE
Ahmet READ
Salih DELETE
Salih UPDATE
Salih READ
Salih READ
Salih CREATE
将获得以下结果的SQL是什么?当简单的COUNT,GROUP BY子句使用Operation类型写成基于ROW。
Name- Total- DELETE- READ- UPDATE CREATE
Ahmet 3 1 1 1 0
Salih 5 1 2 1 1
答案 0 :(得分:1)
select operator,
count(*) as total,
sum(case when operation_type = 'DELETE' then 1 else 0 end) as deletes,
sum(case when operation_type = 'UPDATE' then 1 else 0 end) as updates,
sum(case when operation_type = 'READ' then 1 else 0 end) as reads,
sum(case when operation_type = 'CREATE' then 1 else 0 end) as creates
from operations
group by operator