I have this records:
id | user_id | date
1 | 1 | 2015-01-01
2 | 1 | 2015-01-05
3 | 2 | 2014-01-01
4 | 2 | 2014-01-30
5 | 3 | 2014-01-25
6 | 3 | 2014-02-28
I want to select date ranges to each user, sorted by date range length.
So, in the results I want to get this:
user_id | min_date | max_date
2 | 2014-01-01 | 2014-01-30
3 | 2014-01-25 | 2014-02-28
1 | 2015-01-01 | 2015-01-05
Is it possible to do with sql query?