我有下表,例如:
id....name....fromtime....totime
1.....a.......00:00.......00:09:59
2.....a.......00:10.......00:19:59
3.....a.......00:20.......00:29:59
4.....a.......00:30.......00:39:59
5.....a.......00:40.......00:49:59
我想要检索属于(非问题)的所有记录,并且在00:05和00:25之间,对于上面的示例,是1到3行,留下4和5。
如何使用mysql实现这一目标? 谢谢
答案 0 :(得分:0)
考虑使用'之间的'包含fromtime
和totime
例如,SELECT id, fromtime-totime As "elapsed_time" FROM your_table WHERE elapsed_time BETWEEN 5 AND 25
。或类似的东西。查询将根据列的类型而有所不同。
在此处查看更多信息: http://www.tutorialspoint.com/mysql/mysql-between-clause.htm http://www.geeksengine.com/database/basic-select/arithmetic-operations.php
答案 1 :(得分:0)
AND FromTime> = subtime($ time),'00:10:00') - 获取第一行
AND ToTime< = addtime(TIME($ time),'00:20:00') - 00:20:00是一个例子当然