嗨,大家好,我是红色新手,需要帮助 要求是使用工作日星期六的dw_created_date从表中删除记录。 请帮忙
答案 0 :(得分:0)
我还没有使用过Amazon Redshift,但在阅读documentation之后,你应该找到你的记录:
SELECT *, to_char(dw_created_date, 'D') dayofweek FROM table
“dayofweek”中的数字6表示星期六所以这将删除记录:
DELETE FROM table WHERE to_char(dw_created_date, 'D') = 6
祝你好运!
答案 1 :(得分:0)
Amazon Redshift功能TO_CHAR允许您从Redshift中提取日期部分和有关日期和时间戳的信息,并获取日期部分。
您可以找到有关TO_CHAR function here。
的信息为了从TO_CHAR函数中提取所需的信息,您需要使用适当的日期时间格式字符串。例如," D"返回星期几,DY返回工作日名称的缩写,DAY提供完整拼写的工作日名称。
您可以找到有关date time format strings for Redshift here。
的信息下面我将提供一段快速代码,展示TO_CHAR功能的工作原理。
create table tba (colint integer, colts timestamp) distkey (colint) sortkey (colts);
insert into tba (colint, colts) values (1, '2016-08-08 08:08:08');
insert into tba (colint, colts) values (1, '2016-08-09 09:09:09');
insert into tba (colint, colts) values (1, '2016-08-10 10:10:10');
insert into tba (colint, colts) values (1, '2016-08-11 10:11:11');
insert into tba (colint, colts) values (12, '2016-08-12 12:12:12');
insert into tba (colint, colts) values (13, '2016-08-13 13:13:13');
insert into tba (colint, colts) values (14, '2016-08-14 14:14:14');
insert into tba (colint, colts) values (15, '2016-08-15 15:15:15');
insert into tba (colint, colts) values (16, '2016-08-16 16:16:16');
insert into tba (colint, colts) values (17, '2016-08-17 17:17:17');
insert into tba (colint, colts) values (18, '2016-08-18 18:18:18');
insert into tba (colint, colts) values (20, '2016-08-20 20:20:20');
insert into tba (colint, colts) values (6, '2016-08-06 06:06:06');
select *
, to_char(colts,'D') day_of_week_number
, to_char(colts,'DAY') day_of_week_name
, to_char(colts,'DY') day_of_week_abbrev
from tba;
colint | colts | day_of_week_number | day_of_week_name | day_of_week_abbrev
--------+---------------------+--------------------+------------------+--------------------
15 | 2016-08-15 15:15:15 | 2 | MONDAY | MON
16 | 2016-08-16 16:16:16 | 3 | TUESDAY | TUE
18 | 2016-08-18 18:18:18 | 5 | THURSDAY | THU
1 | 2016-08-08 08:08:08 | 2 | MONDAY | MON
1 | 2016-08-09 09:09:09 | 3 | TUESDAY | TUE
1 | 2016-08-10 10:10:10 | 4 | WEDNESDAY | WED
1 | 2016-08-11 10:11:11 | 5 | THURSDAY | THU
12 | 2016-08-12 12:12:12 | 6 | FRIDAY | FRI
13 | 2016-08-13 13:13:13 | 7 | SATURDAY | SAT
14 | 2016-08-14 14:14:14 | 1 | SUNDAY | SUN
17 | 2016-08-17 17:17:17 | 4 | WEDNESDAY | WED
20 | 2016-08-20 20:20:20 | 7 | SATURDAY | SAT
6 | 2016-08-06 06:06:06 | 7 | SATURDAY | SAT
(13 rows)
最后,但并非最不重要的是,如果您不熟悉Redshift,则应注意两个非常重要的事项。每次删除或更新大量数据时,都应该总是做两件事:
vacuum full tab;
之类的命令。 You can find more info about VACUUM here. ANALYZE VERBOSE TBA;
。 You can find more information about ANALYZE here.