I'm creating a pivot table and I'd like the column names to be something like value1, value2, value3....
CREATE TEMPORARY TABLE temp_table (
id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
value VARCHAR(255),
date DATETIME ,
person_id INT ) ;
Here's the part where I'm naming the column. I tried ID, but with multiple personIDs, it makes the id going in random. I was trying the INTEGER AUTO_INCREMENT, but that throws an error
SET SESSION group_concat_max_len = 1000000 ;
SELECT GROUP_CONCAT(DISTINCT CONCAT('MAX(IF(id = ''', c.id, ''', value, NULL)) AS "', **INTEGER auto_increment**, '"'))
INTO @column_sql1
FROM temp_table c ;
set @sql = concat("select person_id, ", @column_sql1, " from temp_table group by `person_id`");
select @sql;
prepare stmt from @sql;
execute stmt;
Is there any way for each value column to be numbered, so later when I select I can choose the 1st, 2nd, and 3rd column instead of using a different field for the dynamic column name?
I've also tried row_number and many other things. Nothing seems to work.
Thanks for any help.
Error Message: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INTeger auto_increment, '"')) INTO @column_sql1"