我的 SQL 语句看起来像这样
SELECT q.content
FROM questions AS q, user_question_assoc AS uqa
WHERE uqa.user_id=? AND (q.course_id = uqa.course_id
OR q.lesson_id=uqa.lesson_id
OR q.question_id=uqa.question_id)
声明的最后一部分不是我需要的
WHERE uqa.user_id=? AND (q.course_id = uqa.course_id
OR q.lesson_id=uqa.lesson_id
OR q.question_id=uqa.question_id)
实际上我想从下面找出 1 个也是唯一的 MySQL 语句(我试图用人类语言解释))
如果uqa.question_id
不是 0(或 NULL),那么
WHERE uqa.user_id=? AND (q.course_id = uqa.course_id
AND q.lesson_id=uqa.lesson_id
AND q.question_id=uqa.question_id)
如果uqa.lesson_id
不是 0(或 NULL)而是uqa.question_id
0,则
WHERE uqa.user_id=? AND (q.course_id = uqa.course_id
AND q.lesson_id=uqa.lesson_id)
如果 uqa.course_id
不是 0(或 NULL)但uqa.question_id
是uqa.lesson_id
0 那么
WHERE uqa.user_id=? AND q.course_id = uqa.course_id