【发布时间】:2022-02-10 02:59:00
【问题描述】:
df
customer_code contract_code product num_products
C0134 AB01245 toy_1 4
B8328 EF28421 doll_4 2
我想根据 num_products 列中的整数值转换此表,并为每一行生成一个唯一的 id:
预期_df
unique_id customer_code contract_code product num_products
A1 C0134 AB01245 toy_1 1
A2 C0134 AB01245 toy_1 1
A3 C0134 AB01245 toy_1 1
A4 C0134 AB01245 toy_1 1
A5 B8328 EF28421 doll_4 1
A6 B8328 EF28421 doll_4 1
- unique_id 可以是任何随机字符,只要我以后可以在其上使用 count(distinct) 即可。
我读到
generate_series(1,10000) i在更高版本的 Postgres 中可用,但在 Redshift 中不可用
【问题讨论】:
-
generate_series()在 Amazon Redshift 中可用,但它仅在领导节点上运行,这意味着它不能用于访问表数据的查询中。它可用于生成表,但不能与现有表连接。您可以创建一个数字表并加入它。 -
任何提示如何创建与列中的值一样多的数字表?
标签: amazon-web-services amazon-redshift