I’m building upon a solution I developed a while ago – ticket booking. I now need to add a feature to allow tickets to be “held” during purchasing to make them appear as sold to another customer coming to the site (preventing double-booking).
Details on the original tables are in my previous question, MySQL – Trying to count tickets sold for an event. The tickets table now has a held_until DateTime value, and a paid tinyint (bool) value.
I need the events.capacity - COUNT(tickets.id) AS available to now only count those tickets which either:
- Have a
paidvalue of 1 - Have a
paidvalue of 0 andheld_until > now()
I’ve tried adding WHERE and HAVING clauses, but these prevent events where no tickets have been sold from showing. I also had a play around with nested queries but didn’t get anywhere with that either…
Any suggestions?
Modify Andomar’s suggested query (in the other topic) as below :
change
to
Even if all the required information can be found in your other topic, it would probably have been a good idea to repeat some relevant details here.