Relative Content

Tag Archive for sqlsnowflake-cloud-data-platform

Counting number of orders per unique person

Is there a more elegant way to perform calculations of total number of orders per person?
My dataset contains a list of people , date when order was placed, order method, product description. I don’t have an unique order id column (which would make my life easier). I have 1 order per row.
In my sql code i assign a row number to each order in 1rst nested query, then I count max number of orders per person in the 2nd nested query.
At the end, I perform calculations to see how many people placed 1 order only, 2 orders only, etc.

I want to make an condition on dates with window functions

I’m trying to calculate the difference between two events where the condition X is happening and I also have the condition that if the events happens in the same day, the second event will take the previous date not the one earlier on that same date. (Does it make sense ?)

I want to make an condition on dates with window functions

I’m trying to calculate the difference between two events where the condition X is happening and I also have the condition that if the events happens in the same day, the second event will take the previous date not the one earlier on that same date. (Does it make sense ?)