LoginSignup
3
1

More than 5 years have passed since last update.

AWS Redshiftで「n日前までのデータ」を抽出する場合

Posted at

普通にPostgreSQL(RedshiftのベースとなっているRDBMS)の関数を使えば良い。

sql
WHERE visit_time BETWEEN (CURRENT_DATE + INTERVAL '-3 day') AND CURRENT_DATE

CURRENT_DATEはクエリ実行時点での現在時刻を返す、PostgresSQLの関数。
上記例ならば、3日前の0:00から1日前の23:59:59までのデータを取得する。

interval型で指定する日付には他にも年や月など様々な形式が利用できる。
また日付に対してマイナスするだけでなくプラスを使うこともできる。
詳しくは https://www.postgresql.org/docs/9.0/static/functions-datetime.html

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1