Wednesday, 11 September 2013

Looking for a better formula to rank user activity in SQL

Looking for a better formula to rank user activity in SQL

I need to create a table with every single date from 2011 - today and with
every single user login_id and then the user's last activity prior to
"the_date".. i.e. if this person's last activity was on 1/2/13
the_date | login_id | days_since_last_activity
1/2/13 1 0
1/3/13 2 1
1/4/14 3 2
I'm currently using a ROW_NUMBER formula to rank all of the user's
activity based on the date and then pulls RANK = 1 for each the_date and
does a DATEDIFF calculation for column 3... each time and it's making
things very inefficient (as you can imagine).
Is there any other formula that may serve the same purpose?

No comments:

Post a Comment