Skip to content
Advertisement

How can I seperate one column into multiple columns depending on their value when selecting it?

I have a table called assignment_answers, which has the following attributes: assignment_answers_id, question_id and order. The order is an attribute, which can take a value from 0 to 9. I would like for every value that it can take to make it be displayed in a different column. For instance when the order has value 0, then I want it to be displayed in a column called number0. When it has value 1 I want it to be displayed in a column called number1.

Could someone help me with that? So far I have tried this but it does not work:

I get an error saying: ERROR: syntax error at or near “(” LINE 6: (CASE WHEN assessment_questions.”order” = 1

SAMPLE DATA

desired output:

Advertisement

Answer

You can try to use normal CASE WHEN

Query 1:

Results:

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement