I'm trying for the first time in my life to use the PIVOT on my database table. This is the table:
Answers (id_user, id_question, topic, value) VALUES
(1, 1, 'a', 3),
(1, 1, 'b', 3),
(1, 1, 'c', 2),
(1, 2, 'a', 1),
(1, 2, 'b', 2),
(1, 2, 'c', 3),
[...]
(1, 14, 'a', 1),
(1, 14, 'b', 2),
(1, 14, 'c', 1);
But I'm trying to get to this:
Answers (id_user, id_question, topic_A, topic_B, topic_C) VALUES
(1, 1, 3, 3, 2),
(1, 2, 1, 2, 3),
[...]
(1, 14, 1, 2, 1);
with this query I get a generic syntax ERROR near PIVOT
SELECT *
FROM
( SELECT id_user, id_question, topic, value
FROM Answers
WHERE id_user=98
) as risp
PIVOT
( FOR id_question IN ([a],[b],[c])
) AS pvt