Suppose that I have the following two tables:
PRICE
price_id price room_id nr_of_people
1 80 1 1
2 75 1 2
3 90 2 2
4 120 3 3
ROOM
room_id room_no max_people
1 101 2
2 102 3
3 103 4
And, I need the following result:
QUERY_RESULT
price room_no nr_of_people
80 101 1
75 101 2
0 102 1
90 102 2
0 102 3
0 103 1
0 103 2
120 103 3
0 103 4
The tricky part in here is, I need to retrieve price for each people (for 2 people, for 3 people, for 4 people; that is incrementing upto the max_people
defined in the room table), if there is no actual data available in the price table, it should fill in 0 by default. Above illustration should support my explanation.
I am not sure whether the table structure have any logical error.
Any thought/input/help regarding how to resolve the issue is much appreciated.