假设我有以下表结构
CREATE TABLE `calendar` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(255) NOT NULL,
`date` DATE NOT NULL,
PRIMARY KEY (`id`)
)
以及以下数据
INSERT INTO `calendar` (`title`, `date`)
VALUES ('Day 1 - Event 1', '2013-05-01'),
('Day 2 - Event 1', '2013-05-02'),
('Day 2 - Event 2', '2013-05-02'),
('Day 3 - Event 1', '2013-05-03');
我希望将结果集限制为 2 个项目,但不要在同一日期的项目之间削减结果。
SELECT *
FROM `calendar`
WHERE `date` >= '2013-05-01'
LIMIT 2
屈服
('Day 1 - Event 1', '2013-05-01'),
('Day 2 - Event 1', '2013-05-02'),
('Day 2 - Event 2', '2013-05-02')
而不仅仅是
('Day 1 - Event 1', '2013-05-01'),
('Day 2 - Event 1', '2013-05-02')
有任何想法吗?