有一个名为t1的表,并且有列id,created_at,text,例如,如下表所示:
id created text
1 Thu Jun 30 01:00:57 +0000 2016 I like this movie1
2 Thu Jun 30 02:59:57 +0000 2016 I like this movie2
3 Thu Jun 30 03:49:57 +0000 2016 I like this movie3
4 Thu Jun 30 04:59:50 +0000 2016 I like this movie4
5 Thu Jun 30 05:39:57 +0000 2016 I like this movie5
6 Thu Jun 30 06:39:57 +0000 2016 I like this movie6
7 Thu Jun 30 06:29:57 +0000 2016 I like this movie6
8 Thu Jun 30 07:09:57 +0000 2016 I like this movie7
9 Thu Jun 30 07:39:57 +0000 2016 I like this movie8
10 Thu Jun 30 08:39:57 +0000 2016 I like this movie9
11 Thu Jun 30 09:39:57 +0000 2016 I like this movie10
12 Thu Jun 30 10:29:57 +0000 2016 I like this movie11
13 Thu Jun 30 11:29:57 +0000 2016 I like this movie12
12 Thu Jun 30 12:29:57 +0000 2016 I like this movie13
我想选择按小时分隔的数据。 例如,我想选择小时小于或等于06的所有数据,然后我想选择小时大于07的数据。因为列的数据是日期时间形式:Thu Jun 30 12:29:57 + 0000 2016,我不知道如何处理这个问题。谢谢你的帮助!
sql是presto(presto sql):
select id, created, text from t1 where created_at <= 6
答案 0 :(得分:0)
如果您使用的是mssql:
,可以使用datepartselect
id,
created,
text
from
t1
where
datepart(hour, created) <= 6
参考文献:
答案 1 :(得分:0)
我做到了,使用小时(datestamp)可以解决它。
select id, created, text from t1 where hour(created_at) <= 6