我有一个collections表:subscription\u id,transaction\u date\u est,start\u date\u est,end\u date\u est,transaction\u id,invoice\u number,user\u id,transaction\u amount,plan\u code,transaction\u type
我有购买订阅的用户,我为每个订阅生成一个订阅id。每个订阅有1到多个发票。对于每个订阅,我试图找出用户何时通过使用窗口函数传递了100美元的累计金额。我的预期结果:订阅\u id,交易\u日期
我试过:
SELECT subscription_id, MAX(date) transaction_date
FROM (SELECT subscription_id,
SUM(usd_price) LAG (partition by subscription_id
ORDER BY first_transaction_date ASC) AS total
GROUP BY(current_period_started_at)
HAVING BY total >= 100
ORDER BY usd_price)
但是我没有成功提取出用户超过100美元的第一个日期。
1条答案
按热度按时间t2a7ltrp1#
我想你想要: