按时间选择每天12:00:00到18:00:00之间的记录
选择表中时间戳为 2011-08-01-
12:00:00
我尝试使用以下代码
SELECT f.`fly_reg`, RIGHT(f.`start_tid`,8) AS st, f.`start_hight`
FROM vbsk_dk_02.fab_master_flyvedata f
Where st between 12:00:00 AND 18:00:00
的所有记录:但无法让它工作
I've tried to select all records in a table with the timestamp in the dateformat 2011-08-01-
12:00:00
Using the following code:
SELECT f.`fly_reg`, RIGHT(f.`start_tid`,8) AS st, f.`start_hight`
FROM vbsk_dk_02.fab_master_flyvedata f
Where st between 12:00:00 AND 18:00:00
But can't get it to work
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这里有两个问题:
解决了这两个问题后,您将得到:
作为一个选项,如果您不这样做实际上不需要 select 中的时间值,您可以将其删除并将其放在 where 子句中。另外,如果更适合,您可以使用
HOUR()
函数。通过这两项更改,您的查询将简化为:这更加简洁:)
You've got two issues here:
TIME()
function to extract the time part of the datatimeWith those two issues addressed, you get:
As an option, if you don't actually need the time value in the select, you can remove it and just have it in the where clause. Also, you can use the
HOUR()
function if that suits better. With those two changes in, your query would simplify to:which is a lot neater :)
如果您已将时间存储在“时间戳”或“日期时间”类型的列中,则可以选择小时之间的一系列记录,如下所示:
我使用此设置对此进行了测试:
If you have stored the time in a column of type "Timestamp" or "Datetime", you can select a range of records between hours like this:
I tested this with this setp up: