I have entries:
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 for each user, sorted by the length of the date range.
So, in the results I want to get the following:
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?
http://sqlfiddle.com/#!15/f958b
source share