Hello guys I need help cause I’m not really an expert with complex queries in MySql… What I need is this:
I am developing a small analytics system… what I have is one table like this
±-----------±------------±-----------±------------±-----------+
| ID | IP | page | lastpage | time |
±-----------±------------±-----------±------------±-----------+
| 1 | x.x.x.x | … | … | 0001 |
±-----------±------------±-----------±------------±-----------+
| 2 | x.x.x.x | … | … | 1111 |
±-----------±------------±-----------±------------±-----------+
| 3 | x.x.x.x | … | … | 1113 |
±-----------±------------±-----------±------------±-----------+
| 3 | x.x.x.x | … | … | 1114 |
±-----------±------------±-----------±------------±-----------+
| 3 | x.x.x.x | … | … | 1120 |
±-----------±------------±-----------±------------±-----------+
| 2 | x.x.x.x | … | … | 1114 |
±-----------±------------±-----------±------------±-----------+
| 1 | x.x.x.x | … | … | 0004 |
±-----------±------------±-----------±------------±-----------+
Ok ID is the session id it’s one for each user… IP, page and lastpage are not relevant… what i’m interested in is the difference between the min time and the max time for each distinct ID… how do I do that?
example:
±-----------±------------±-----------±------------+
| ID | MIN | MAX | DIFF |
±-----------±------------±-----------±------------+
| 1 | 0001 | 0004 | 3 |
±-----------±------------±-----------±------------+
| 2 | 1111 | 1114 | 3 |
±-----------±------------±-----------±------------+
| 3 | 1113 | 1120 | 17 |
±-----------±------------±-----------±------------+
The time column is unix timestamp btw…
Thank you guys!