Mysql 在日期之间标记为假日

Mysql 在日期之间标记为假日,mysql,sql,Mysql,Sql,所以我有这个DTR表。我想使用具有开始日期和结束日期的假日来标记日期(添加一列以标记为假日),如图2所示。有没有人有解决方案来实现这一点 CREATE TABLE IF NOT EXISTS `payroll_dtr` ( `id` int(11) NOT NULL AUTO_INCREMENT, `employmentRecordId` int(11) DEFAULT NULL, `employeeId` varchar(50) DEFAULT NULL, `date` dat

所以我有这个
DTR
表。我想使用具有开始日期和结束日期的假日来标记日期(添加一列以标记为假日),如图2所示。有没有人有解决方案来实现这一点

CREATE TABLE IF NOT EXISTS `payroll_dtr` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `employmentRecordId` int(11) DEFAULT NULL,
  `employeeId` varchar(50) DEFAULT NULL,
  `date` date NOT NULL,
  `timeinAM` time DEFAULT NULL,
  `timeoutAM` time DEFAULT NULL,
  `timeinPM` time DEFAULT NULL,
  `timeoutPM` time DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `employmentRecordId` (`employmentRecordId`),
  KEY `employeeId` (`employeeId`)
) ENGINE=InnoDB AUTO_INCREMENT=73 DEFAULT CHARSET=latin1;

-- Dumping data for table db_hrmis.payroll_dtr: ~71 rows (approximately)
/*!40000 ALTER TABLE `payroll_dtr` DISABLE KEYS */;
INSERT INTO `payroll_dtr` (`employmentRecordId`, `employeeId`, `date`, `timeinAM`, `timeoutAM`, `timeinPM`, `timeoutPM`) VALUES
    (10, 'DRB201822210', '2018-02-01', '08:30:00', '12:00:00', '13:00:00', '17:30:00'),
    (10, 'DRB201822210', '2018-02-02', '08:30:00', '12:00:00', '13:00:00', '17:30:00'),
    (10, 'DRB201822210', '2018-02-05', '08:30:00', '12:00:00', '13:00:00', '17:30:00'),
    (10, 'DRB201822210', '2018-02-06', '08:30:00', '12:00:00', '13:00:00', '17:30:00'),
    (10, 'DRB201822210', '2018-02-07', '08:30:00', '12:00:00', '13:00:00', '17:30:00'),
    (10, 'DRB201822210', '2018-02-08', '08:30:00', '12:00:00', '13:00:00', '17:30:00'),
    (10, 'DRB201822210', '2018-02-09', '08:30:00', '12:00:00', '13:00:00', '17:30:00'),
    (10, 'DRB201822210', '2018-02-12', '08:34:44', '12:00:00', '13:00:00', '17:30:00'),
    (10, 'DRB201822210', '2018-02-13', '06:30:00', '12:00:00', '13:00:00', '17:30:00'),
    (10, 'DRB201822210', '2018-02-14', '08:35:00', '12:05:00', '13:00:00', '17:30:00'),
    (10, 'DRB201822210', '2018-02-15', '08:30:00', '12:00:00', '13:05:00', '17:30:00'),
    (10, 'DRB201822210', '2018-02-19', '08:30:00', '12:00:00', '13:00:00', '17:30:00'),
    (10, 'DRB201822210', '2018-02-20', '08:30:00', '12:00:00', '13:00:00', '17:30:00'),
    (10, 'DRB201822210', '2018-02-21', '08:30:00', '12:00:00', '13:00:00', '17:30:00'),
    (10, 'DRB201822210', '2018-02-22', '08:30:00', '12:00:00', '13:00:00', '17:30:00'),
    (10, 'DRB201822210', '2018-02-23', '08:30:00', '12:00:00', '13:00:00', '17:30:00'),
    (10, 'DRB201822210', '2018-02-26', '08:30:00', '12:00:00', '13:00:00', '17:30:00'),
    (10, 'DRB201822210', '2018-02-27', '08:30:00', '12:00:00', '13:00:00', '17:30:00'),
    (10, 'DRB201822210', '2018-02-28', '08:30:00', '12:00:00', '13:00:00', '17:30:00');
图1。

图2

CREATE TABLE IF NOT EXISTS `inf_calendar_of_events` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(50) NOT NULL,
  `start` date DEFAULT NULL,
  `end` date DEFAULT NULL,
  `timeStart` time DEFAULT NULL,
  `timeEnd` time DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=latin1;

-- Dumping data for table db_hrmis.inf_calendar_of_events: ~6 rows (approximately)
/*!40000 ALTER TABLE `inf_calendar_of_events` DISABLE KEYS */;
INSERT INTO `inf_calendar_of_events` (`title`, `start`, `end`, `timeStart`, `timeEnd`) VALUES
    ('Test', '2018-02-16', '2018-02-20', NULL, NULL);

期望的输出,但不是使isHoliday=1,而是希望它是来自Holiday表的日期


谢谢你的帮助。抱歉,我没有提供完整的数据。

看起来像一个简单的连接

select d.id,dte,
         case when dte between date_from and date_to then 'x'
         else ''
         end holiday
from dates d
cross join holiday_table
where entity_id = 3 and dte between '2018-02-14' and '2018-02-21'

+------+------------+---------+
| id   | dte        | holiday |
+------+------------+---------+
| 6620 | 2018-02-14 |         |
| 6621 | 2018-02-15 | x       |
| 6622 | 2018-02-16 | x       |
| 6623 | 2018-02-17 | x       |
| 6624 | 2018-02-18 | x       |
| 6625 | 2018-02-19 | x       |
| 6626 | 2018-02-20 | x       |
| 6627 | 2018-02-21 |         |
+------+------------+---------+

我有个问题,伙计,如果我的假日表是空的,它也会返回空的,但我希望它仍然显示日期/记录,