Skip to content
Advertisement

Date distinct count over week

Im trying to get a distinct count of user ids logs per day with every week as a partition for the distinct identification. e.g. if one user logs on Friday/Saturday of week 1, and on Monday/Friday of week 2, i want to have a column that counts 1 in Friday and 0 in Saturday week 1, and 1 in Monday and 0 in Friday week 2.

If i have the following data:

https://i.stack.imgur.com/COf69.png

I expect this result:

https://i.stack.imgur.com/kTRdu.png

Im working with Presto, and have tried with dense_rank() solutions but with no avail.

Advertisement

Answer

You can use window functions and aggregation:

Better yet, using the standard where clause to aggregate functions, which Presto supports:

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement