select customer_id, product_ts, count(*) as num_products_before
from (select t.*,
min(case when product = :product then timestamp end) over (partition by customerid) as product_ts
from t
) t
where timestamp < product_ts
group by customer_id, product_ts;
1条答案
按热度按时间ckocjqey1#
如果我理解正确,您可以使用窗口函数和聚合: