How to group rows into two groups in sql?
Posted
by
user1055638
on Stack Overflow
See other posts from Stack Overflow
or by user1055638
Published on 2012-10-29T16:56:00Z
Indexed on
2012/10/29
17:00 UTC
Read the original article
Hit count: 144
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!
© Stack Overflow or respective owner