I have a problem for creating a query for postgres(strictly speaking its redshift).
table data is below.
the table is PARTITION BY user_id ORDER BY created_at desc
data
user_id| x | y | min | created_at
-------+---+---+------+---------------------
1| 1 | 1 | 1 | 2015-01-15 17:26:53
1| 1 | 1 | 2 | 2015-01-15 17:26:54
1| 1 | 1 | 3 | 2015-01-15 17:26:55
1| 2 | 1 | 10 | 2015-01-16 02:46:21
1| 1 | 1 | 15 | 2015-01-16 02:46:22
1| 3 | 3 | 11 | 2015-01-16 03:01:44
1| 3 | 3 | 2 | 2015-01-16 03:02:06
2| 1 | 1 | 3 | 2015-01-16 03:02:12
2| 2 | 1 | 4 | 2015-01-16 03:02:15
2| 2 | 1 | 7 | 2015-01-16 03:02:18
and what I want is below
ideal result
user_id| x | y | sum_min |
-------+---+---+----------+
1| 1 | 1 | 6 |
1| 2 | 1 | 10 |
1| 1 | 1 | 15 |
1| 3 | 3 | 13 |
2| 1 | 1 | 3 |
2| 2 | 1 | 11 |
If I use simply group by user_id, x, y, the result of will be
user_id| x | y | sum_min |
-------+---+---+----------+
1| 1 | 1 | 21 |
:| : | : | : |
this is not good for me:(
x,y, and created_atfor grouping or what ???1| 1 | 1 | 6 |and1| 1 | 1 | 15 |are comes in different rows (i.e row1and3) ???