sql - How to capture different values in the same column with a similar ID into one row with specific column indicators -


i need capture yes or no answer question codes columns serve indicator each specific question code. question codes set values , sake of example can 'a', 'b', or 'c'.

any appreciated, looking forward answers sql gurus can think of!

example input table:

    id  question code   yesorno     1                     yes     1         b             no     1         c             no     2                     no     2         b             yes     2         c             yes     3                     no     3         b             no     3         c             yes 

desired table/view:

    id  a_answer    b_answer    c_answer     1   yes         no          no     2   no          yes         yes     3   no          no          yes 

to clarify in sql server.

you can perform conditional aggregation:

select     id,     a_answer = max(case when [question code] = 'a' yesorno end),     b_answer = max(case when [question code] = 'b' yesorno end),     c_answer = max(case when [question code] = 'c' yesorno end) tbl group id; 

online demo


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -