2

I have a rather interesting problem which I first thought would be straight-forward, but it turned out to be more complicated.

I have data like this:

Date             User ID
2012-10-11         a
2012-10-11         b
2012-10-12         c
2012-10-12         d 
2012-10-13         e
2012-10-14         b
2012-10-14         e
...                ...

Each row has a Date, User ID couple which indicates that that user was active on that day. A user can appear on multiple dates and a date will have multiple users -- just like in the example. I have millions of rows like this which cover a time range of about 90 days.

Here's the question: For each day, I want to get the number of users who have not been active for the past 10 days. For instance, if the user "a" was active on 2012-05-31 and but hasn't been active on any of the days between 06-01 and 06-10, I want to count this user on 6/10. I wouldn't count him again on the following days though unless he becomes active and disappears again.

Can I do this in SQL or would I need to some kind of script to organize the data the way I want. What would be your recommendations? I use Hive.

Thank you so much!

4

1 に答える 1