Sorry for my bad English.
I'm trying to GROUP BY
on bunch of user_id
's with considering its sequences. I'll try to explain you what exactly I want :
table: orders
+-----------+----------+------------+
| id | user_id | amount |
+-----------+----------+------------+
| 1 | 100 | 5 |
| 2 | 100 | 5 |
| 3 | 100 | 10 |
| 4 | 101 | 15 |
| 5 | 101 | 10 |
| 6 | 101 | 5 |
| 7 | 102 | 5 |
| 8 | 100 | 5 |
| 9 | 100 | 10 |
| 10 | 102 | 10 |
+-----------+----------+------------+
What I want is :
+-----------+----------+------------+----------------+
| user_id | count | total_amount | id_range |
+-----------+----------+------------+----------------+
| 100 | 3 | 20 | 1,3 |
| 101 | 3 | 30 | 4,6 |
| 102 | 1 | 5 | 7,7 |
| 100 | 2 | 15 | 8,9 |
| 102 | 1 | 10 | 10,10 |
+-----------+----------+------------+----------------+
What I've tried so far :
SELECT user_id, count(user_id) as count, sum(amount) as total_amount FROM `orders` GROUP By user_id
But it just GROUP BY on all records, regardless of its sequences.