1

Suppose I've got the following table:

Room | Seats | Occupied
-----------------------
a1      20       10
b2      15       15
c3      45       30
d4      20       15
e5      10       10

I have a trouble (just have no idea how that can be done) generating a SELECT statement that will merge some of the rooms and will sum up their values and will return the following:

Room | Seats | Occupied
-----------------------
a1      20       10
b2c3d4  80       60
e5      10       10

How can this be done?

Thank you in advance!

4

1 に答える 1

1
select room,
       sum(seats) as seats,
       sum(occupied) as occupied
from your_table
group by case when room in ('b2', 'c3', 'd4') 
              then 'b2c3d4'
              else room
         end
于 2012-11-05T18:19:21.610 に答える