Skip to content
Advertisement

Daily active counts of THING from rows detailing change of THING

Say I have a table of people who have used my service on a day N and a table describing what theme the users have changed to. There’s no table available telling me what theme they are currently using. What I would like to do is to see that on a daily basis.

So let’s say the changes table looks like this.

The activity table has just the user_ID and a date they accessed the service reported.

Now what I would like to do is join the first table to the second one so the theme they are using on an active date would be listed there.

How do I achieve this? Assume there can be an unlimited amount of themes.

Advertisement

Answer

One method is a correlated subquery, but I’m not sure if Presto supports this:

A perhaps more efficient method is to use left join but to calculate the “end” date for each change:

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