【发布时间】:2020-02-06 07:34:26
【问题描述】:
这是我的下表,即 machine_shifts
CREATE TABLE `machine_shifts` (
`date` date NOT NULL,
`shift_start_time` time DEFAULT NULL,
`shift_end_time` time DEFAULT NULL,
`shift` varchar(20) NOT NULL,
`updated_on` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`date`,`shift`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
数据是
insert into `machine_shifts` (`date`, `shift_start_time`, `shift_end_time`, `shift`, `updated_on`) values('2010-01-01','00:00:00','06:00:00','C','2020-01-29 15:37:26');
insert into `machine_shifts` (`date`, `shift_start_time`, `shift_end_time`, `shift`, `updated_on`) values('2010-01-01','06:00:00','13:00:00','A','2020-01-29 15:37:26');
insert into `machine_shifts` (`date`, `shift_start_time`, `shift_end_time`, `shift`, `updated_on`) values('2010-01-01','13:00:00','24:00:00','B','2020-01-29 15:37:26');
insert into `machine_shifts` (`date`, `shift_start_time`, `shift_end_time`, `shift`, `updated_on`) values('2010-01-02','00:00:00','06:00:00','C','2020-01-29 15:37:26');
insert into `machine_shifts` (`date`, `shift_start_time`, `shift_end_time`, `shift`, `updated_on`) values('2010-01-02','06:00:00','13:00:00','A','2020-01-29 15:37:26');
insert into `machine_shifts` (`date`, `shift_start_time`, `shift_end_time`, `shift`, `updated_on`) values('2010-01-02','13:00:00','24:00:00','B','2020-01-29 15:37:26');
insert into `machine_shifts` (`date`, `shift_start_time`, `shift_end_time`, `shift`, `updated_on`) values('2010-01-03','00:00:00','06:00:00','C','2020-01-29 15:37:26');
insert into `machine_shifts` (`date`, `shift_start_time`, `shift_end_time`, `shift`, `updated_on`) values('2010-01-03','06:00:00','13:00:00','A','2020-01-29 15:37:26');
insert into `machine_shifts` (`date`, `shift_start_time`, `shift_end_time`, `shift`, `updated_on`) values('2010-01-03','13:00:00','24:00:00','B','2020-01-29 15:37:26');
假设我有一台机器在 2010:01:01 时间 07:01:00 开始并在 2010:01 结束: 03 时间 10:00:00。
我想查询上表,得到开始日期和结束日期之间的记录。
预期输出:
标记线之间是预期的输出。
【问题讨论】:
-
输出会是什么?
-
@juergend 编辑了问题并提到了预期的输出。
-
@KishoreKumarKorada 问题还不够清楚。
-
@ArifulIslam 我已经编辑了我的问题。如果您能理解,请检查一下吗?