I have a table with columns:
- user_id int
- code int
- int value
And I want to create a pivot table that looks like this:
- user_id int
- valueA int
- valueB int
In the details table, the value A will correspond, for example, code 5, and the value B will correspond, for example, code 6, so I'm looking for something like:
insert into the summary (user_id, valueA, valueB) VALUES (SELECT ??? from the details);
The problem is that I am looking at several rows from the details table to populate one row in the summary table.
For example, if I had the following lines in detail:
1 5 100 1 6 200 2 5 1000 2 6 2000
In the summary table, I want to get the following:
1 100 200 2 1000 2000
Any ideas?
mysql pivot
Jack
source share