Insert data from 1 column to many columns in another table (using 1 line) in sql I have a table (table1) in which IDs of transactions, transaction state (there are 10 total states) and their time of entering that state are stored.

I want to feed this data into another table which would have 11 columns: 1 for the Transaction ID and the other 10 for the time that they enter each state.

I want to write this as an SQL query. I looked for it and found

insert into table2(ID, s1, s2, s3, s4 ... )
select ID, time from table1
where [];


but I don't have 10 different columns in table1 to copy from as there are 10 different rows corresponding to each ID and each state.

Please help me out in doing this is 1 query.

I am new to SQL. Thanks in advance.
Find an example of a pivot table here.