我面临一个 SQL SELECT 问题:
有一个问题,这个问题有一个答案,这个答案有一个下一个问题,依此类推......这是我的查询:
SELECT Q.question, A.answer, A.nextQuestion as 'next question' from answers A join questions Q on A.nextQuestion = V.questionId
order by Q.question;
这是上述查询的输出:
Question 1 | Answer 1 | 2
Question 1 | Answer 2 | 2
Question 2 | Answer 1 | 1
Question 2 | Answer 2 | 1
所以现在“下一个问题”是一个数字......但我想将该数字解析为下一个问题文本(Q.question)......我怎样才能做到这一点?
我想要这样的东西:
Question 1 | Answer 1 | Question 2
Question 1 | Answer 2 | Question 2
Question 2 | Answer 1 | Question 1
Question 2 | Answer 2 | Question 1
提前致谢!!
我正在使用 MySQL。
这是我的表结构:
表“问题”
+------------------+
| Field |
+------------------+
| questionId |
| question |
+------------------+
表“答案”
+------------------+
| Field |
+------------------+
| answerId |
| answer |
| nextQuestion |
+------------------+