For a table like this named Activity:
| player_id | device_id | event_date | games_played |
|---|---|---|---|
| 1 | 2 | 2016-03-01 | 5 |
| 1 | 2 | 2016-03-02 | 6 |
| 2 | 3 | 2017-06-25 | 1 |
| 3 | 1 | 2016-02-02 | 0 |
| 3 | 4 | 2018-07-03 | 5 |
I wonder why the following query only returns the result on the first row:
select player_id, datediff(event_date, min(event_date)) as date_diff
from Activity
Returns:
| player_id | date_diff |
|---|---|
| 1 | 28 |
I was expecting the fourth row will be returned as it has the minimum event_date, something like
| player_id | date_diff |
|---|---|
| 2 | 0 |
I think you should have 3 separate
selectquery, one to find the min event date in the entire table, one to add the result as a column in the query result, final one to calculate the date differenceFrom your sample data, running the query would get: