其中一列的数据格式如下:
column_name_a:
abcd/date=2018-01-01/part-0001-asdfasdfasdf
abcd/date=2018-01-01/part-0002-asdfasdfasdf
abcd/date=2018-01-02/part-0001-asdfasdfasdf
abcd/date=2018-01-02/part-0002-asdfasdfasdf
abcd/date=2018-01-03/part-0001-asdfasdfasdf
abcd/date=2018-01-03/part-0002-asdfasdfasdf
abcd/date=2018-01-03/part-0003-asdfasdfasdf
abcd/date=2018-01-03/part-0004-asdfasdfasdf
.....
现在,我需要按天或部件号获取文件计数。
如何编写查询?
答案 0 :(得分:1)
除了Nate的答案,您还可以多次使用split_part来获得所需的内容:
要获取日期:
select split_part(split_part('abcd/date=2018-01-01/part-0001-asdfasdfasdf','/',2),'=',2)
要获取零件号:
select split_part(split_part('abcd/date=2018-01-01/part-0001-asdfasdfasdf','/',3),'-',2)
答案 1 :(得分:0)
使用split_part。字符串中仍将带有“ date =”。
date = split_part(column_name_a,'/',2)
part_number = split_part(column_name_a,'/',3)
详细信息在这里... https://docs.aws.amazon.com/redshift/latest/dg/SPLIT_PART.html