I have a database table containing responses to questions from users. Each question has a request and a response timestamp. The questions are asked in random order. Some users abandoned before completing all the questions and thus don't have subsequent response records.
I didn't capture the order in which the questions were asked for each user, but the sequence could be derived from the request timestamps (SELECT * FROM responses ORDER BY id_user, request_ts;
).
I'm using MySQL, so I don't have ROW_NUMBER() as an available function. How would I go about getting the equivalent output, and have the counting restart on each id_user?
That is, for user_id=1, I want responses with values 1,2,..n ordered by request_ts, and then user_id=2 would have their responses with values 1,2,..n; and so on.
Ultimately, I want to get a set of data of aggregated average duration for each nth question (i.e. average duration for first question asked, ditto second question asked, etc).
+-----+-----+-------+
| Seq | Num | Avg_D |
+-----+-----+-------+
| 1 | 20 | 00:36 |
| 2 | 20 | 00:31 |
| 3 | 19 | 00:31 |
| 4 | 20 | 00:25 |
| 5 | 18 | 00:24 |
| 6 | 20 | 00:24 |
| 7 | 20 | 00:23 |
| 8 | 20 | 00:25 |
+-----+-----+-------+
This can then be used to show participant drop-off, survey fatigue, etc.