嗨,我有这样的 sql 代码:
SELECT vote_id, (SELECT type FROM vote_types WHERE id= 1) AS answer
FROM poll_answers
WHERE question_id =1;
它向我显示:
如何提出这个问题,以便它可以在第二行显示另一个 answer2 which vote_id = 2 而不再显示 answer1 ?
谢谢
嗨,我有这样的 sql 代码:
SELECT vote_id, (SELECT type FROM vote_types WHERE id= 1) AS answer
FROM poll_answers
WHERE question_id =1;
它向我显示:
如何提出这个问题,以便它可以在第二行显示另一个 answer2 which vote_id = 2 而不再显示 answer1 ?
谢谢
我不知道你的桌子。但我认为 - 查询应该是
SELECT vote_id, type as answer
FROM poll_answers, vote_types
WHERE question_id =1 and question_id = id;
SELECT poll_questions.id, vote_types.type AS answer
FROM poll_questions
JOIN poll_answers ON poll_questions.id = poll_answers.question_id
JOIN vote_types ON poll_answers.vote_id = vote_types.id
WHERE poll_questions.referendum_id = 1