cumulative orders

rndmnm
New Member

Hi,

I need some help finding cumulative orders value in MySQL.

0 1 167
1 REPLY 1

Hello @rndmnm and welcome!

In pure SQL, you would need to go through a subquery and a window function. Something like this:

with temp_table as (

select

date_trunc('week', created_at) as created_week
, count(distinct order_id) as orders_count

from orders

group by 1)

select 

created_week
, orders_count
, sum(orders_count) over (order by created_week asc rows between unbounded preceding and current row) as cumul_orders_count

from temp_table

group by 1,2

But you can easily do that in LookML/Table calculation already without going through a SQL query.

Top Labels in this Space
Top Solution Authors