Php 如何在记录while子句中显示其他数据,其中为null?
我有一张考勤表Php 如何在记录while子句中显示其他数据,其中为null?,php,mysql,Php,Mysql,我有一张考勤表 CREATE TABLE `msattendance` ( `id` int(11) NOT NULL AUTO_INCREMENT, `regnum` varchar(20) DEFAULT NULL, `reg_b` varchar(20) DEFAULT NULL, `in_hr` time NOT NULL, `out_hr` time NOT NULL, `in_info` varchar(20) DEFAULT NULL
CREATE TABLE `msattendance` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`regnum` varchar(20) DEFAULT NULL,
`reg_b` varchar(20) DEFAULT NULL,
`in_hr` time NOT NULL,
`out_hr` time NOT NULL,
`in_info` varchar(20) DEFAULT NULL,
`out_info` varchar(20) DEFAULT NULL,
`in_date` date DEFAULT NULL,
`out_date` date DEFAULT NULL,
`in_mechine` varchar(3) DEFAULT NULL,
`out_mechine` varchar(3) DEFAULT NULL,
`upload_date` date DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `id` (`id`),
KEY `nik` (`nik`),
KEY `in_date` (`in_date`),
KEY `out_date` (`out_date`),
KEY `in_hr` (`in_hr`),
KEY `out_hr` (`out_hr`)
)
表上的示例值为:
+----+-----------+-------+----------+----------+---------+----------+------------+------------+------------+-------------+---------------------+---------------------+-------------+
|id | regnum | regu b | in | hr | out | hr | in | u info | out | in | date | out | in | u mechine | out | mechine | upload | time 2 | upload | date|
+----+-----------+-------+----------+----------+---------+----------+------------+------------+------------+-------------+---------------------+---------------------+-------------+
| 1 | 216115657 | 5657 | 07:36:00 | 15:17:00 | 1 | 2 | 2017-02-18 | 2017-02-18 | 2 | 2 | 2017-03-16 08:09:15 | 2017-03-16 08:11:42 | 2017-03-16 |
|2 | 216115657 | 00:00:00 | 18:59:00 |空| 2 |空| 2017-02-17 |空| 2 |空| 2017-03-16 08:09:15 | 2017-03-16|
|3 | 216115657 | 00:00:00 | 07:41:00 |空| 2 |空| 2017-05-25 |空| 4 |空| 2017-05-30 15:32:45 | 2017-05-30|
| 4 | 216115657 | 5657 | 07:41:00 | 16:38:00 | 1 | 2 | 2017-05-26 | 2017-05-26 | 2 | 2 | 2017-05-30 15:51:07 | 2017-05-30 16:01:39 | 2017-05-30 |
|5 | 216115657 | 00:00:00 | 16:40:00 |空| 2 |空| 2017-05-25 |空| 4 |空| 2017-05-30 15:51:07 | 2017-05-30|
| 10 | 216115657 | 5657 | 07:44:00 | 16:45:00 | 1 | 2 | 2017-11-22 | 2017-11-22 | 2 | 4 | 2017-11-23 10:01:38 | 2017-11-23 10:07:04 | 2017-11-23 |
| 11 | 216115657 | 5657 | 07:43:00 | 16:41:00 | 1 | 2 | 2017-11-23 | 2017-11-23 | 2 | 3 | 2017-11-23 10:07:04 | 2017-11-24 13:13:27 | 2017-11-23 |
| 12 | 216115657 | 5657 | 07:43:00 | 16:33:00 | 1 | 2 | 2017-11-24 | 2017-11-24 | 3 | 4 | 2017-11-24 13:13:27 | 2017-11-25 09:50:05 | 2017-11-24 |
|13 | 216115657 | 00:00:00 | 14:13:00 | 1 | 2 |空| 2017-11-25 |空| 4 | 2017-11-25 09:50:05 | 2017-11-27 10:32:51 | 2017-11-25|
| 14 | 216115657 | 5657 | 07:43:00 | 16:32:00 | 1 | 2 | 2017-11-27 | 2017-11-27 | 3 | 4 | 2017-11-27 10:32:51 | 2017-11-28 14:00:27 | 2017-11-27 |
|15 | 216115657 | 07:43:00 | 00:00:00 | 1 |空| 2017-11-28 |空| 4 |空| 2017-11-28 14:00:27 |空| 2017-11-28|
+----+-----------+-------+----------+----------+---------+----------+------------+------------+------------+-------------+---------------------+---------------------+-------------+
您需要说-日期在这两个日期之间-或空
SELECT * FROM `msattendance`
WHERE ((in_date between '2017-11-23' and '2017-11-28')
or in_date is null)
and reg_b = '5657'
您需要说-日期介于这些日期之间-或为空
SELECT * FROM `msattendance`
WHERE ((in_date between '2017-11-23' and '2017-11-28')
or in_date is null)
and reg_b = '5657'
这就是你需要的
下面的查询将返回日期中不存在或在给定日期范围内的所有用户
SELECT *
FROM `msattendance`
WHERE (in_date IS NULL OR in_date >= '2017-11-23')
AND in_date <= '2017-11-28'
AND reg_b = '5657'
选择*
从“mAttentince”开始
其中(输入日期为空或输入日期>='2017-11-23')
这就是你需要的
下面的查询将返回日期中不存在或在给定日期范围内的所有用户
SELECT *
FROM `msattendance`
WHERE (in_date IS NULL OR in_date >= '2017-11-23')
AND in_date <= '2017-11-28'
AND reg_b = '5657'
选择*
从“mAttentince”开始
其中(输入日期为空或输入日期>='2017-11-23')
在日期中只添加或在日期中为空
只添加或在日期中为空
我尝试使用该代码,但我以前日期的旧数据也会出现,不仅仅是我需要的日期范围你能举个例子吗(将其添加为问题的编辑)我无法重现相同的内容,除非我更改SQL语句中的日期,否则这两个语句都不会返回2017-11-22的记录。我会尝试使用该代码,但我以前日期的旧数据也会出现,不仅是我需要的日期范围。您可以演示一个示例(将其添加为对您的问题的编辑)我无法复制相同的内容,除非我更改SQL语句中的日期,否则这两条语句都不会返回2017-11-22的记录。