0

我有 2 个测验表:“问题”和“答案”。每个问题都有 4 个答案。我想要求 50 个随机问题。我试试这个,但它返回的问题少于 50 个。

(我需要所有 50 个问题和 200 个答案的所有字段)。

SELECT Q.*, A.* FROM questions Q
LEFT JOIN answers A ON Q.pid = A.pid
WHERE Q.pid >= RAND() * (SELECT MAX(pid) FROM questions)
AND  Q.lid IN $array
GROUP BY Q.pid
LIMIT 50
4

1 回答 1

1

尝试以下操作:

 SELECT y.* 
   FROM 
      ( SELECT * 
          FROM questions 
         ORDER 
            BY RAND() LIMIT 2
      ) x 
   JOIN answers y 
     ON y.question_id = x.question_id 
  ORDER  
     BY x.question_id;
于 2013-03-20T14:58:20.897 回答