Skip to content

Instantly share code, notes, and snippets.

@jpadilla
Created January 25, 2012 03:40
Show Gist options
  • Save jpadilla/1674570 to your computer and use it in GitHub Desktop.
Save jpadilla/1674570 to your computer and use it in GitHub Desktop.
SELECT DISTINCT outlet_name,
IFNULL(SUM(reservation_pax), 0) AS reserved,
outlet_max_capacity,
( outlet_max_capacity - IFNULL(SUM(reservation_pax), 0) ) AS available
FROM `outlets`
LEFT JOIN `reservations`
ON `reservations`.reservation_outlet_id = `outlets`.outlet_id
AND reservation_date = '2011-09-22'
AND HOUR(reservation_time) = '17'
GROUP BY outlet_id
SELECT DISTINCT outlet_name,
IFNULL(SUM(reservation_pax), 0) AS reserved,
outlet_max_capacity,
( outlet_max_capacity - IFNULL(SUM(reservation_pax), 0) ) AS available
FROM `outlets`
LEFT JOIN `reservations`
ON `reservations`.reservation_outlet_id = `outlets`.outlet_id
AND reservation_date = CURDATE()
AND HOUR(reservation_time) = HOUR(CURTIME())
GROUP BY outlet_id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment