Share
How to write a query to get cumulative spending?
Question
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Assume you are given a table for spending activity by product type which has column names as order_id, user_id, product_id, spend, date . How to write a query to calculate the cumulative spend for each product over time in chronological order.
Answers ( 2 )
select product_id, sum(spend) over (partition by product_id, user_id order by product_id) as Comm_Spend from table;
Ꮋello i am kavin, its my first time to commenting anyplace, when i read this post i thought i
could also make comment due to this good post.