0

我试图查询和总结的数据是持卡人的日常交易数据。我试图先每天汇总,然后再累积。我可以按天成功汇总,但是当我添加以下行时:

sum(custs_spent_at_least_once) over (order by day rows unbounded preceding) as cum_total

我收到错误“关系卡不存在”

我有一个不同的查询,它使用相同的代码行执行类似的操作。

这是我的代码,可以按天累计汇总。

with spenders as (  

  select
      [first_trans_date:aggregation] as period, 
      count(member_uuid) as custs_spent_at_least_once
    from
      (
        select distinct member_uuid, min(postdate_and_posttime) as first_trans_date
        from
          (
            (
              select
                card_reference_number, postdate_and_posttime
                , dense_rank() over(partition by card_reference_number order by postdate_and_posttime) as rank
              from
                i2c.posted
              where
                [is_crn_post_launch] and [is_merchant_trans]
              group by card_reference_number, postdate_and_posttime
            )
            as posc
            left join card on card.i2c_ref_id = posc.card_reference_number
          )
      group by member_uuid
      ) 
    group by period 
  order by period desc

)

select 
  period 
  , custs_spent_at_least_once
  , sum(custs_spent_at_least_once) over (order by day rows unbounded preceding) as cum_total
from spenders
order by period desc
4

1 回答 1

0

你没有专栏day。您可能打算period

select period, custs_spent_at_least_once,
       sum(custs_spent_at_least_once) over (order by period rows unbounded preceding) as running_total
from spenders
order by period desc;
于 2019-09-26T13:57:49.913 回答