SQL 日期之间的红移查询
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45087803/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Redshift query between date
提问by newleaf
I'm quite new to Redshift SQL.
我对 Redshift SQL 很陌生。
select * from myredshift_tbl
where local_date between \'2016-01-01\' and \'2017-02-01\';
But got this error:
但是得到了这个错误:
[amazon][500310] invalid operation syntax error at or near "\". I believe Redshift use single quote and I need to escape single quote.
[amazon][500310] “\”处或附近的无效操作语法错误。我相信 Redshift 使用单引号,我需要转义单引号。
回答by Yusuf Hassan
If the column local_date
is in date format, use:
如果该列local_date
是日期格式,请使用:
select * from myredshift_tbl
where local_date between '2016-01-01' and '2017-02-01';
If the column local_date
is timestamp:
如果列local_date
是时间戳:
select * from myredshift_tbl
where local_date between '2016-01-01 00:00:00' and '2017-02-01 23:59:59';
回答by Golokesh Patra
SELECT * FROM schemaName.TableName WHERE datetime > '2017-02-09
00:00:00' AND datetime < '2017-06-09 00:00:00';
The above query Works with Redshift to fetch all the entries in a table.
上面的查询与 Redshift 一起使用以获取表中的所有条目。
NOTE:The table I applied the query on had column/field 'datetime' of type 'timestamp'.
注意:我应用查询的表具有“时间戳”类型的列/字段“日期时间”。
I tested this query on Redshift with the help of Workbench J.
我在 Workbench J 的帮助下在 Redshift 上测试了这个查询。