Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Sycopons
Starting Member
4 Posts |
Posted - 2012-02-08 : 02:46:21
|
I would like to display all RoomType and the total room(s),available room(s), and occupied room(s) Here is my sample tableRoomsRoomNo RoomTypeID Availability100 1 Yes101 1 No102 1 No103 2 Yes104 2 NoRoomTypeRoomTypeID RoomName RoomPrice1 Single 1002 Double 2003 Tripe 300xSycopons |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-02-08 : 02:54:34
|
[code]select rt.RoomTypeID, rt.RoomName, total = count(*) available = count(case when r.Availability = 'Yes' then r.RoomNo end), occupied = count(case when r.Availability = 'No' then r.RoomNo end)from RoomType rt inner join Rooms r on rt.RoomTypeID = r.RoomTypeID group by rt.RoomTypeID, rt.RoomName[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
Sycopons
Starting Member
4 Posts |
Posted - 2012-02-08 : 03:49:30
|
Thank you so much khtan..God Bless. I really Appreciate your help..xSycopons |
 |
|
|
|
|