-1

I have a table as follow OPERATIONS

OPERATOR-OPERATION TYPE
Ahmet   DELETE
Ahmet   UPDATE
Ahmet   READ
Salih   DELETE
Salih   UPDATE
Salih   READ
Salih   READ
Salih   CREATE

What SQL will be to get following result? When simple COUNT, GROUP BY clauses used Operation types written as ROW based.

Name- Total- DELETE- READ- UPDATE  CREATE
Ahmet 3      1       1     1       0
Salih 5      1       2     1       1 
Ahmet Karakaya
  • 9,899
  • 23
  • 86
  • 141
  • 2
    It depends on your RDBMS. Could you please tag your question with this? This is known as a PIVOT operation - there are quite a few questions on SO relating to this. – Ben Jun 05 '14 at 13:28

1 Answers1

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
juergen d
  • 201,996
  • 37
  • 293
  • 362