I've got a SQL Server 2008 R2 database with around 500 million rows of data in it, it currently looks like this
ID Eventtype
201 1
201 3
201 4
201 1
201 1
664 1
664 0
664 1
664 3
I can't seem to find a query that will provide the data back in this format:
ID Event0 Event1 Event2 Event3 Event4
201 0 3 0 1 1
664 1 2 0 1 0
This is as far as I've gotten at this point:
select distinct ID as ID, count(EventType)
from database.dbo.events
group by questID, EventType
which spits data back to me like:
ID EventType
201 0
201 3
201 0
201 1
201 1
664 1
664 2
664 0
etc.
This does display all the data I need, but the formatting and guesswork involved in trying to figure out which EventType
is which is quite frustrating.
Can anyone suggest a better query that will return the data in a good format?