每天在12:00:00至18:00:00间隔内按时间选择记录 [英] Select records by time in interval between 12:00:00 and 18:00:00 on every day

查看:96
本文介绍了每天在12:00:00至18:00:00间隔内按时间选择记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在dateformat中选择时间戳记中的所有记录2011-08-01 -

I've tried to select all records in a table with the timestamp in the dateformat 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

但无法让它工作

推荐答案

这里有两个问题:


  1. 您不能在where子句中引用列别名。相反,您必须在where子句中重复计算

  2. 使用 TIME()函数来提取数据时间的时间部分

  1. You can't refer to column aliases in the where clause. Instead, you have to repeat your calculation in the where clause
  2. Use the TIME() function to extract the time part of the datatime

有了这两个问题,您将得到:

With those two issues addressed, you get:

select
    f.fly_reg,
    TIME(f.start_tid) AS st,
    f.start_hight 
    FROM vbsk_dk_02.fab_master_flyvedata f 
where TIME(f.start_tid) between '12:00:00' AND '18:00:00'

作为一个选项,如果在选择中实际不需要时间值,则可以将其删除,并将其放在where子句中。另外,如果适合更好的话,你可以使用 HOUR()函数。通过这两个更改,您的查询将简化为:

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:

select *
FROM vbsk_dk_02.fab_master_flyvedata
where HOUR(f.start_tid) between 12 and 18

这是一个很整洁的:)

这篇关于每天在12:00:00至18:00:00间隔内按时间选择记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆