redshift: count distinct customers over window partition

前端 未结 2 854
花落未央
花落未央 2021-02-15 01:49

Redshift doesn\'t support DISTINCT aggregates in its window functions. AWS documentation for COUNT states this, and distinct isn\'t supported for any o

2条回答
  •  生来不讨喜
    2021-02-15 02:09

    While Redshift doesn't support DISTINCT aggregates in its window functions, it does have a listaggdistinct function. So you can do this:

    regexp_count(
       listaggdistinct(customer_id, ',') over (partition by field2), 
       ','
    ) + 1
    

    Of course, if you have , naturally occurring in your customer_id strings, you'll have to find a safe delimiter.

提交回复
热议问题