I have a page audit table that records which pages a user has accessed. Given an specific page, I need to find what previous page the user has accessed and what was the most accessed.
For example, the FAQ Page_ID is 3. I want to know if it is more frequently accessed from the First Access page (ID 1) or Home page (ID 5).
Example:
Page Audit Table (SQL Server)
ID | Page_ID | User_ID
1 | 1 | 6
2 | 3 | 6
3 | 5 | 4
4 | 3 | 4
5 | 1 | 7
6 | 3 | 7
7 | 1 | 5
8 | 3 | 2 --Note: previous user is not 2
9 | 3 | 5 --Note: previous page for user 5 is 1 and not 3
Looking for Page_ID = 3, I want to retrieve:
Previous Page | Count
1 | 3
5 | 1
Note: I've looked some similar questions here (like that one), but it didn't help me to solve this problem.