我有一点问题。我有一个这样的数据库布局:
customer
customer_id, name, age, etc...
customer_survey_question
id, category, caption, type
customer_survey_answer
id, customer_id, customer_survey_question_id, answer
我需要像这样提取他们的答案:
name, age, etc..., question 1, question 2, question 3, etc...
现在我可以做一个子查询:
SELECT
`customer`.*,
(
SELECT `answer`
FROM `customer_survey_answer`
WHERE `customer_survey_answer`.`customer_id`=`customer`.`customer_id`
AND `id`=1
) AS `question_1`,
(
SELECT `answer`
FROM `customer_survey_answer`
WHERE `customer_survey_answer`.`customer_id`=`customer`.`customer_id`
AND `id`=2
) AS `question_2`,
....
但是有 14 个问题,我需要能够很快地做到这一点,并将问题扩展到 80 多个。最好的方法是什么?