Redshift-将UTC数据转换为其他时区

时间:2018-09-25 11:20:27

标签: sql case amazon-redshift

我正在尝试将数据从UTC转换为欧洲各个时区。我正在使用一个case语句,并且只查找case语句中的第一个条件,而没有检查其他条件。

SELECT sale_id,appointment_time,timezone,
   case when timezone = 'EDT' then (appointment_time + interval '-4' HOUR * 1)
        when timezone = 'BST' then (appointment_time + interval '1' HOUR * 1)
        when timezone = 'CEST' then (appointment_time + interval '2' HOUR * 1)
        when timezone = 'EEST' then (appointment_time + interval '3' HOUR * 1)
        when timezone = 'MSK' then (appointment_time + interval '3' HOUR * 1)
        when timezone = 'WEST' then (appointment_time + interval '1' HOUR * 1) 
        else null
        end as NewTime
   FROM sales

谁能建议我要去哪里错了。谢谢

2 个答案:

答案 0 :(得分:1)

您错过了其他操作,只需在末尾添加并使用ArrayList<Thumbnail> tmp = new ArrayList<>(); for (Thumbnail thumbnail : videoList1){ for (Giphy giphy : giphyList) { if (thumbnail.getVideoID().equals(giphy.getVideoID())) { thumbnail.setThumbUp(giphy.getThumbUp()); thumbnail.setThumbDown(giphy.getThumbDown()); tmp.add(thumbnail); } } } videoList1.addAll(tmp); 函数

dateadd

答案 1 :(得分:1)

为什么不使用内置的convert_timezone函数。这样会更快,因为您不需要使用案例

SELECT sale_id, appointment_time, timezone, 
  convert_timezone(timezone, appointment_time) as NewTime
FROM sales