Reputation: 160
I have a mysql table structure like that:
id int primary key
name varchar
start_time float
the data may be like that:
id name start_time
1 tt1 20.3
2 tt3 19.5
3 tt1 23.1
4 tt1 40.1
5 tt4 20.5
6 tt3 44.2
I want the result set grouped by name and list all start_time in the each group like that:
name start_times
tt1 (20.3,23.1,40.1)
tt3 (19.5,44.2)
tt4 (20.5)
And the order of the result set is the number of start_time in each group.
Thanks in advance :)
Upvotes: 1
Views: 436
Reputation: 160833
You could use GROUP_CONCAT FUNCTION.
SELECT name, GROUP_CONCAT(start_time ORDER BY start_time) AS start_times
FROM your_table GROUP BY name
ORDER BY COUNT(start_time)
Upvotes: 3