mysql 日期介于_mysql查询找到时间介于from和to之间

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');

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值