I have simple tables of data where event times are assoictaed to an id. Each id can have 0, 1 or more event times.
So my data looks like this
ID EventTime
----------
1 15
3 49
3 78
5 68
6 62
7 85
7 86
I would like to a turn my data side ways and have the following
ID Event1 Event2 Event3 Event4 etc
----------------------------------------
1 15
3 49 78
5 68
6 62
7 85 86
I've looked at crosstab, but I think it relates to fixed lists, whereas mine differs depending upon how many, if any observations there were.
Might be Mysql56 and I use a Heidi front end.
So looking at the replies (thank you) I guess I need to use PIVOT.
Any assistance in the syntax would be greatly appreciated. All in there about 800 thousand eventIds, and up to around a max of 20 eventtimes per id. The events should ideally be ordered by time, ie lowest to highest.
Thanks
You could solve it using a function or stored procedure, to build up the entire query dynamically.
The sqlfiddle
I show you a how by using the function buildQuery, see below!
create table events and data
create function buildQuery()
execute the function
run results
SqlFiddle
The sqlfiddle