我有2個表StudentEnrollmentDetails
和StudentExamAnalysis
。使用這兩個表我需要以下輸出。MySQL的:需要下面的輸出
SchoolId Rank StudentName Percentage
1 1 ABC 70
1 2 ABD 69.56
1 3 ABC 69
2 1 ABC 71
2 2 ABD 68.56
2 3 ABC 63
我有一個基本的查詢。我需要在飛行中產生排名。
SELECT SED.SchoolId, @s:[email protected]+1 serial_number, SAED.*
FROM StudentAnswerExamData SAED INNER JOIN StudentEnrollmentDetails SED ON SED.StudentEnrollmentDetailsId = SAED.StudentEnrollmentDetailsId
INNER JOIN (SELECT @s:= 0) AS s
WHERE SED.ExamCategoryId = 2 AND SED.ExamId = 2 AND SED.Standard = 5 AND SED.CompanyId = 2
ORDER BY SED.SchoolId, SAED.Percentage DESC;
Table Definition
Table: studentenrollmentdetails
FIELD TYPE
StudentEnrollmentDetailsId BIGINT(20)
StudentId BIGINT(20)
StudentRegNo BIGINT(20)
ExamCategoryId INT(11)
ExamId BIGINT(20)
SchoolId BIGINT(20)
SourceId BIGINT(20)
SourceAccountId BIGINT(20)
Standard INT(11)
Amount DECIMAL(10,2) IsOptionEnabled TINYINT(1)
ExamSessionId BIGINT(20)
EnrollmentFormPath VARCHAR(300)
Division VARCHAR(10)
TransactionTime DATETIME
CompanyId INT(11)
STATUS INT(11)
UploadedBy BIGINT(20)
FileId BIGINT(20)
LastModifiedBy BIGINT(20)
LastModifiedByTime DATETIME
SchoolName VARCHAR(100)
SchoolLocation VARCHAR(100)
MarkForDelete TINYINT(1)
Table: studentanswerexamdata
Column Information
FIELD TYPE
StudentAnswerExamDataId BIGINT(20)
StudentId BIGINT(20)
StudentEnrollmentDetailsId BIGINT(20)
ExamCategoryId INT(10)
ExamId BIGINT(20)
Standard INT(10)
CompanyId INT(10)
UploadedById BIGINT(20)
UploadedDateTime DATETIME
ModifiedById BIGINT(20)
ModifiedDateTime DATETIME
MarkForDelete TINYINT(1)
SeatNo BIGINT(20)
NoOfCorrect INT(11)
NoOfInCorrect INT(11)
NoOfMissing INT(11)
MarksScored DECIMAL(6,2)
Percentage DECIMAL(5,2)
SchoolRank INT(11)
DistrictRank INT(11)
StateRank INT(11)
NationalRank INT
太好了。我需要{..whatever ..} - 你的表格定義在哪裏?輸入數據的樣本在哪裏? –