1

私はネテザを使用しています。私はマーケティング データ、特にクーポンを扱っています。現在、毎日のクーポン利用者を個別に数えています。大きな問題ではない。ただし、これまでの個別の償還者の数を取得したいと思います。顧客が異なる日に引き換える可能性があるため、1 日の引き換え者の合計だけではないことに注意してください。

私は目を閉じて願い事をし、うまくいくことを願って次のクエリを実行しました。

select redemption_date
      ,count(distinct(customer_id)) as day_redeemers
      ,count(distinct(customer_id)) over (partition by null rows unbounded preceding) as cml_redeemers
from coupon_history
group by 1
order by 1

しかし、Netezza は不平を言います: ERROR [HY000] ERROR: Attribute CUSTOMER_ID must be GROUPed or used in an aggregate function

...そして、私は目を閉じて願い事をし、次のことを実行します (group by への追加に注意してください)。

select redemption_date
      ,count(distinct(customer_id)) as day_redeemers
      ,count(distinct(customer_id)) over (partition by null rows unbounded preceding) as cml_redeemers
from coupon_history
group by 1,customer_id
order by 1

Netezza は次のように訴えています。

ERROR [HY000] ERROR:  DISTINCT aggregate not allowed in window with ORDER BY or frame specification

このエラーにより、内部的に Netezza が遷移をカウントするために customer_id を注文しているのではないかと考えられます。しかし、それは私が次に何を試すべきかについて、ある種の途方に暮れたままにします. シンプルなものを望んでいましたが、どうやら私の幸運な日ではありません。

元のクエリを機能させる方法についてのアイデア、または別のアプローチに関する提案はありますか?

ありがとう!

4

1 に答える 1

3

ブルート フォース、つまり相関サブクエリにいつでも頼ることができます。

select redemption_date,
       count(distinct(customer_id)) as day_redeemers,
       (select count(distinct ch2.customer_id)
        from coupon_history ch2
        where ch2.redemption_date <= ch.redemption_date
       ) as cml_redeemers
from coupon_history ch
group by 1
order by 1;

もちろん、パフォーマンスはそれほど良くありません。

編集:

これにアプローチする別の方法は、各顧客の最初の償還日を取得し、累積合計を使用することです。

select minrd,
       sum(count(*)) over (order by minrd) as cml_redeemers
from (select ch.customer_id, min(redemption_date) as minrd
      from coupon_history ch
      group by ch.customer_id
     ) ch
group by minrd;
于 2014-12-12T01:27:00.767 に答える