1

我试图从以下 mysql 语句中获取唯一问题的计数,但每次我尝试将 count(q.id) 添加为 questionCount 时,该语句只返回一个结果。我显然做错了什么,但我无法弄清楚它是什么。

http://www.sqlfiddle.com/#!2/34906/58

希望有人可以提供帮助。

史蒂夫

4

2 回答 2

1

只需将查询的第二行编辑为此:

select
  count(distinct FinalQA.QUESTION_ID)   from.....
于 2012-06-08T09:24:30.030 回答
0

It appears you want the total questions "stamped" on every row... for example you are auto-generating a test and want it to show "Out of 5 questions" in the output. To simplify this, since you KNOW you want 5 questions via your WHERE clause, I would slightly adjust it to...

select
      FinalQA.*
   from
      ( select 
              5 as TotalQuestionsOffered,
              QWithAllAnswers.*,
              ... rest of query ) FinalQA
   where
      FinalQA.ARankSeq <= FinalQA.TotalQuestionsOffered
于 2012-06-08T13:20:06.780 回答