Redshift DISTINCT在其窗口函数中不支持聚合.用于COUNT声明此状态的AWS文档,并且distinct不支持任何窗口函数.
我希望本年度的月度和年初至今独特的客户数量,并且还按交通渠道和所有渠道的总数进行划分.由于客户可以多次访问我只需要计算不同的客户,因此Redshift窗口聚合将无济于事.
count(distinct customer_id)...group by,但这只会给我四个所需的结果.union all.我希望这不是唯一的解决方案.这就是我在postgres(或Oracle)中写的内容:
select order_month
, traffic_channel
, count(distinct customer_id) over(partition by order_month, traffic_channel) as customers_by_channel_and_month
, count(distinct customer_id) over(partition by traffic_channel) as ytd_customers_by_channel
, count(distinct customer_id) over(partition by order_month) as monthly_customers_all_channels
, count(distinct customer_id) over() as ytd_total_customers
from orders_traffic_channels
/* otc is a table of dated transactions of customers, channels, and month of order */
where to_char(order_month, …Run Code Online (Sandbox Code Playgroud)