3 个答案:
答案 0 :(得分:1)
您使用的是值而不是列名
您可以使用以下查询。您可以根据需要更改价值。
根据您的需要首先更改时间值。
int[] to = {R.id.student_view};
SimpleCursorAdapter mCurAdapter = new SimpleCursorAdapter(getContext(),R.layout.list_template, mCursor, from, to,0);的第一个选项
Where
第二个选项是SELECT * FROM `table` WHERE from_time >= '00:00:00' and to_time <= '23:59:59'
between
答案 1 :(得分:0)
对于超过午夜的to_times,您可以添加24小时然后进行测试。例如
drop table if exists t;
create table t(from_time time, to_time time);
insert into t values
('18:00:00','20:00:00'),
('18:00:00','01:00:00'),
('16:00:00','18:00:00');
select from_time,to_time,
case when '19:00:00' between
from_time and
if(to_time < from_time,
addtime(to_time,'24:00:00'),
to_time)
then 'true'
else 'false'
end as truefalse
from t;
+-----------+----------+-----------+
| from_time | to_time | truefalse |
+-----------+----------+-----------+
| 18:00:00 | 20:00:00 | true |
| 18:00:00 | 01:00:00 | true |
| 16:00:00 | 18:00:00 | false |
+-----------+----------+-----------+
3 rows in set (0.00 sec)
答案 2 :(得分:0)
您的问题未显示所选时间的来源。它是否在列中,是用户在SQL中设置还是通过代码发送的?
如果在SQL中设置了时间,那么执行此操作的方法如下:
SET @mytime := '19:00:00';
SELECT * FROM `table` WHERE CAST(@mytime AS TIME) BETWEEN from_time AND to_time;
其中@mytime是用户设置变量,并假设from_time和to_time是时间格式。
我的上述测试表如下:
CREATE TABLE `timetest` (
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`from_time` time DEFAULT NULL,
`to_time` time DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
测试数据为:
INSERT INTO `timetest` (`id`, `from_time`, `to_time`) VALUES
(1, '09:00:00', '11:00:00'),
(2, '06:30:00', '14:00:00'),
(3, '14:29:10', '16:12:18'),
(4, '09:11:17', '23:00:01'),
(5, '18:00:00', '23:59:59'),
(6, '01:12:00', '11:59:44');