How to group rows into two groups in sql?
- by user1055638
Lets say I have such a table:
id|time|operation
1 2 read
2 5 write
3 3 read
4 7 read
5 2 save
6 1 open
and now I would like to do two things:
Divide all these records into two groups:
1) all rows where operation equals to "read"
2) all other rows.
Sum the time in each group.
So that my query would result only into two rows.
What I got so far is:
select
sum(time) as total_time,
operation
group by
operation
;
Although that gives me many groups, depending on the number of distinct operations.
How I could group them only into two categories?
Cheers!