[英]MySql query extract value with between syntax
These are my rows in MySql database table: 这些是我在MySql数据库表中的行:
+------------+----------+-------------+
| theDate | theHour | theUserCode |
+------------+----------+-------------+
| 2015-11-16 | 06:30:00 | XX2111905 |
| 2015-11-16 | 21:30:37 | XX2112111 |
| 2015-11-16 | 22:21:29 | XX2112111 |
| 2015-11-16 | 17:15:18 | XX2142122 |
| 2015-11-16 | 04:22:13 | XX2146905 |
| 2015-11-16 | 15:15:00 | XX2146905 |
| 2015-11-16 | 21:26:00 | XX2148516 |
+------------+----------+-------------+
7 rows in set
I need extract from this table the rows with theHour
between 15:00:00
and 03:00:00
. 我需要从这个表中提取与行
theHour
之间的15:00:00
和03:00:00
。
I have tried this Sql query but in output I have the Empty set
. 我已经尝试过此Sql查询,但在输出中有
Empty set
。
SELECT
theDate,
theHour,
theUserCode
FROM
`tblUserRegistered`
WHERE
theDate BETWEEN DATE_SUB('2015-11-16', INTERVAL 1 DAY)
AND '2015-11-16'
AND theHour BETWEEN '15:00:00'
AND '03:00:00'
ORDER BY
theUserCode,
theDate,
theHour ASC;
Please help me, thank you so much in advance. 请帮助我,非常感谢。
I used the HOUR()
function in my query below to handle the check by hour. 我在下面的查询中使用了
HOUR()
函数来按小时处理检查。 This query will include records later than 3pm (15 hours), or earlier than 3am (03 hours). 该查询将包含晚于下午3点(15小时)或早于凌晨3点(03小时)的记录。
SELECT theDate, theHour, theUserCode
FROM tblUserRegistered
WHERE theDate BETWEEN DATE_SUB('2015-11-16', INTERVAL 1 DAY) AND '2015-11-16'
AND (HOUR(theHour) >= 15 OR HOUR(theHour) <= 3)
ORDER BY theUserCode, theDate, theHour ASC
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.