Ok, newb SQL guy here.
I have a vb.net mission and one of my queries has me stumped. It can be done in code, but trying to do as much as possible in SQL
The basic concept is a room booking application. Clients book hotel rooms, need to count how many clients in rooms and how many rooms booked.
Client booking database:
RoomRecord| ClientID|.......etc......| RoomWithClientID | .....RoomType|
Design wise, there is only ever going to be one client rooming with one client, hence not doing 1 to many table (Right or wrong?)
So a record may look like:
ClientID | RoomWithClientID |RoomType
123..........125....................Twin
124..........0.......................Single
125..........123....................Twin
126..........127....................Double
127..........126....................Double
128..........0.......................Double
129..........0.......................Double
eg - 123 / 125 are partners, same twin room
124, single person, single room
However, 128 is a single person who wants a double room.
I cant just count the number of clients and /2 to get the number of rooms, nor count the number of double rooms and /2, as there may be clients without partners in double rooms.
eg as above, I have 4 clients in double rooms, however require 3 double rooms as 2 have no partner
Ideally I want to return DISTINCT records where if ClientID = RoomWithClientID, then we only show one of those 2 ClientID's .
Then once I have one client record (for both partners), I know I have one room type filled and can count the rooms
Does that make sense?
I have a vb.net mission and one of my queries has me stumped. It can be done in code, but trying to do as much as possible in SQL
The basic concept is a room booking application. Clients book hotel rooms, need to count how many clients in rooms and how many rooms booked.
Client booking database:
RoomRecord| ClientID|.......etc......| RoomWithClientID | .....RoomType|
Design wise, there is only ever going to be one client rooming with one client, hence not doing 1 to many table (Right or wrong?)
So a record may look like:
ClientID | RoomWithClientID |RoomType
123..........125....................Twin
124..........0.......................Single
125..........123....................Twin
126..........127....................Double
127..........126....................Double
128..........0.......................Double
129..........0.......................Double
eg - 123 / 125 are partners, same twin room
124, single person, single room
However, 128 is a single person who wants a double room.
I cant just count the number of clients and /2 to get the number of rooms, nor count the number of double rooms and /2, as there may be clients without partners in double rooms.
eg as above, I have 4 clients in double rooms, however require 3 double rooms as 2 have no partner
Ideally I want to return DISTINCT records where if ClientID = RoomWithClientID, then we only show one of those 2 ClientID's .
Then once I have one client record (for both partners), I know I have one room type filled and can count the rooms
Does that make sense?