Sql Query
SELECT respondant.respondant_firstname as first_name,
question.question_id as question_id,
answer.answer_id,
answer.answer_text,
answer.answer_rate,
answer.answer_nps,
question_radio.question_radio_text as opt
FROM question
LEFT JOIN answer on answer.answer_question_id = question.question_id
LEFT JOIN question_radio on answer.answer_question_radio_id = question_radio.question_radio_id
LEFT JOIN respondant on answer.answer_respondant_id = respondant.respondant_id
WHERE question.question_feedback_id = 1
ORDER BY question.question_id, answer.answer_id
输出:
first_name question_id answer_id answer_text answer_rate answer_nps opt
RM 1 1 5 NULL NULL
Y 1 3 0 NULL NULL
Ben 1 5 0 NULL NULL
akash 1 8 2.5 NULL NULL
RM 2 2 0 4 NULL
Y 2 4 0 3 NULL
Ben 2 6 0 0 NULL
akash 2 9 0 0 NULL
Ben 3 7 Thanks 0 0 NULL
akash 3 10 0 0 NULL
我需要输出为:
first_name question_id answer_id answer_text answer_rate answer_nps opt
RM 1 1 5 NULL NULL
Y 1 3 0 NULL NULL
Ben 1 5 0 NULL NULL
akash 1 8 2.5 NULL NULL
RM 2 2 0 4 NULL
Y 2 4 0 3 NULL
Ben 2 6 0 0 NULL
akash 2 9 0 0 NULL
RM 3 NULL 0 0 NULL
Y 3 NULL 0 0 NULL
Ben 3 NULL ThankS 0 0 NULL
akash 3 NULL 0 0 NULL
在最后的第三和第四行中没有id 3,但我需要替换为3和其他值,因为这两行必须为null
答案 0 :(得分:0)
你想做的事情相当复杂。您希望每个响应者和问题都有一行,然后填写响应者的详细信息。我的猜测是你希望answer_id
填写,如果可用的话。也就是说,你想要的结果应该{&1}}用于" Ben"和"阿卡什"。
以下查询使用响应者和问题之间的answer_id
生成所有行。然后它会带来更多信息:
cross join