大家好,
我一直在尝试找出如何在一个座位块中选择15张票。
编辑:问题是 - 如何查找给定尺寸(例如3x5)的所有空闲座位的矩形区域?
下面是我的表格,查询选择了4个连续座位(或15个或其他),这很好...
但我想要做的是选择15个座位,它们可能分散在多行上,即3 x 5,但我希望它们被连在一起,即在同一个块里。
row 9 ..(some seats)..[5 seats]..(some seats)..
row 8 ..(some seats)..[5 seats]..(some seats)..
row 7 ..(some seats)..[5 seats]..(some seats)..
也就是说,它们将成为3排位于彼此前面。第9排的座位是从10到25,第8排的座位是从10到25,第7排的座位是从10到25。
还需要考虑一下,如果一个座位块有不同数量的座位,例如,一个角落的座位块可能弯曲,后面的座位比前面的座位多。
关于SQL语句、算法或PHP代码等方面的任何指导都可以。我已经绞尽了脑汁,大部分时间都在思考这个问题。
CREATE TABLE `seats` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`event_id` int(11) DEFAULT NULL,
`performance` int(11) DEFAULT NULL,
`block` int(11) DEFAULT NULL,
`row` int(11) DEFAULT NULL,
`seat` int(11) DEFAULT NULL,
`status` int(10) DEFAULT 1,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=utf8;
到目前为止我的查询返回X个座位的块的组合。
SELECT a.event_id, a.performance, a.block,
a.row, a.seat AS start_seat,
a.seat + (4 - 1) AS end_seat,
4 AS requested_seats,
a.id AS start_allocation_id
FROM seats a
LEFT JOIN seats b ON
a.event_id = b.event_id AND
a.performance = b.performance AND
a.block = b.block AND
a.row = b.row AND
a.seat < b.seat AND
b.seat < a.seat + 4 AND
b.status = 1
WHERE a.status = 1 AND
a.event_id = 1
GROUP BY a.seat
HAVING COUNT(b.seat) + 1 = 4
ORDER BY performance
提前致谢,如需更多信息,请随时提问!
00011111000
,所有的1都是可用的。 - Dor