我可以根据'date'
或'dateLast'
来查询数量,但不了解当日期在'date'
和'dateLast'
之间时如何获取数量
该查询有效并显示了基本逻辑,但是它不使用'endDate'
确定两者之间的日期。如何在两个日期之间进行迭代以检查值(7)以收集过期的值?
样本数据:
CREATE TABLE test (
`id` int(20) NOT NULL,
`date` date DEFAULT NULL,
`dateLast` date DEFAULT NULL,
`mid` int
);
INSERT INTO `test` (`id`, `date`, `dateLast`, `mid`) VALUES
(1, '2019-03-19', '2019-03-21', 22),
(2, '2019-03-18', '2019-03-25', 22),
(3, '2019-03-19', '2019-03-20', 22),
(4, '2019-03-19', '2019-03-20', 22),
(5, '2019-03-19', '2019-03-20', 22),
(6, '2019-03-19', '2019-03-20', 22),
(7, '2019-03-19', '2019-03-20', 22),
(8, '2019-03-19', '2019-03-20', 22),
(9, '2019-03-19', '2019-03-20', 22);
我的查询:
SELECT
reservations.date,
COUNT(*) AS Qty
FROM
reservations
WHERE
reservations.mid = 22
AND Qty >=7
GROUP BY
reservations.date