1

I have 2 tables which provides list of all rooms and booked rooms. Can I Subtract the Room_Count with Room_Used?

Select type,count(room_number)as Room_Count from room group by type
Type | Room Count

A1 | 10

A2 | 10

Select type,count(room_number)as Booked_Count from room_used group by type

Type | Booked_Count

A1 | 5

So I tried this Query

select a.type,count(a.room_count)-count(b.room_booked)as room_avail from room a,room_used b where a.room=b.room_used

Type | Room_avail

A1 | 5

It seems fine at start,but how to display the un-substracted ones,like this?

Type | Room_avail

A1 | 5

A2 | 10

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
bara
  • 11
  • 2

1 Answers1

0
SELECT a.type,count(a.room_count)-count(ISNULL(b.room_booked,0)) as Room_Count 
FROM   room a LEFT JOIN room_used b on a.room = b.room_used

What's the difference between INNER JOIN, LEFT JOIN, RIGHT JOIN and FULL JOIN?

Community
  • 1
  • 1
niketshah90
  • 199
  • 1
  • 10