의 조항이 내 쿼리 인 경우 :선택 탑 내부 조인 개수 및 SQL
ExamID StudentID ItemNo StudentAnswer Score
1006 1 1 A 25
1005 1 2 B 30
1004 1 3 A 35
내가 뭘 원하는 것은 그것이 StudentAnswer = 경우 2를 반환합니다 수 있습니다 :
SELECT TOP 3 tablestudentanswer.examid,
tablestudentanswer.studentid,
tablestudentanswer.itemno,
tablestudentanswer.studentanswer,
tablescore.score
FROM tablestudentanswer
INNER JOIN tablescore
ON tablestudentanswer.studentid = tablescore.studentid
AND tablestudentanswer.examid = tablescore.examid
WHERE tablestudentanswer.examid = 1
AND tablestudentanswer.itemno = 1
ORDER BY tablescore.score ASC
그것은이 테이블 반환 'A'와 1이면 StudentAnswer = 'B' 맨 위에 내 검색어에 아무런 문제가 없습니다. 내가 묻는 것은 그 쿼리에 무엇을 추가해야 하는가이다.
내 마음에 2를 반환해야하지만이 오류가 있습니다.
Select COUNT(*) From (
Select Top 3 TableStudentAnswer.ExamID, TableStudentAnswer.StudentID, TableStudentAnswer.ItemNo, TableStudentAnswer.StudentAnswer, TableScore.Score
from TableStudentAnswer
Inner join TableScore on TableStudentAnswer.StudentID=TableScore.StudentID and TableStudentAnswer.ExamID=TableScore.ExamID
where TableStudentAnswer.ExamID=1 and TableStudentAnswer.ItemNo=1
Order By TableScore.Score Asc) where TableStudentAnswer.StudentAnswer = 'A'
그것은 반환해야합니다 :
2
제발 도와주세요!
귀하의 요구 사항을 명확히 설명해주십시오. 무엇이 잘못 되었습니까? –
질문에 아무런 문제가 없으므로 원하는 출력을 얻기 위해 쿼리에 추가 할 내용을 모른다. StudentAnswer = 'A'이면 2이고 StudentAnswer = 'B'인 경우 1입니다. – user3083026
더 혼란을 피하기 위해 실제로 원하는 결과 세트를 추가하십시오. 모든 행과 열과 그 값을 가져야합니다. 그것은 일반적으로 우리가 당신이 대답을 알고 싶어 대답하고 있는지 확인하는 가장 좋은 방법입니다 :) – Luaan