Advertisement
Guest User

Untitled

a guest
Aug 21st, 2015
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. tried it but it doesn't work in this case
  2.  
  3. if I change total_rooms of bookings for the record 1 to 4
  4.  
  5. `
  6. SELECT r.id AS roomID, r.name, r.no_of_rooms, r.no_of_rooms - COALESCE(t.bookedCnt,0) AS available_rooms FROM rooms AS r LEFT JOIN ( SELECT room_id, COUNT(*) AS bookedCnt FROM bookings WHERE `start` <= '2015-08-14' AND `end` >= '2015-08-11' GROUP BY room_id ) AS t ON r.id = t.room_id
  7. `
  8.  
  9. `
  10. roomID name no_of_rooms available_rooms
  11. 1 Lake View 4 3
  12. 2 Royale 2 1
  13. 3 Skyview 6 6
  14. `
  15.  
  16. the data for the available rooms should be 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement