Mysql 我的sql时间范围选择
我的桌子Mysql 我的sql时间范围选择,mysql,database,Mysql,Database,我的桌子 starttime | endtime | id 10:30 11:30 1 11:30 12:30 2 14:30 16:30 3 15:30 16:30 4 例如,我需要在给定的时间段中查找id 说 我使用的语句 select id from table where STR_TO_DATE(starttime,'%h:
starttime | endtime | id
10:30 11:30 1
11:30 12:30 2
14:30 16:30 3
15:30 16:30 4
例如,我需要在给定的时间段中查找id
说
我使用的语句
select id from table where STR_TO_DATE(starttime,'%h:%i')>='10:30' and STR_TO_DATE(endtime,'%h:%i')<='22:30';
从STR_TO_DATE(开始时间,%h:%i')>='10:30'和STR_TO_DATE(结束时间,%h:%i')所在的表中选择id
STR_到_日期(开始时间,%h:%i)
您使用的是格式%h,根据是:
小时(01..12)
本质上,12以上的所有内容都是无效的(返回NULL)。
并且,您为这些ID提供了大于12的值
使用说明符
%H
格式为00-23的小时数
或者说明符
%k
0-23小时。只是好奇,o/p代表什么?
select id from table where STR_TO_DATE(starttime,'%h:%i')>='10:30' and STR_TO_DATE(endtime,'%h:%i')<='22:30';
select id from table where STR_TO_DATE(starttime,'%H:%i')>='10:30' and STR_TO_DATE(endtime,'%H:%i')<='12:30';