2012-07-28 53 views
0

使用下面的SQL語句,我可以根據需要獲得有關學生的所有信息,除了一個問題是重複記錄時,實際上每個學生只需輸入記錄。如何在多個表中使用mssql中的distinct?

 
Student ID  Year level Semester 
20012-000001 20012-20013 1 
20012-000001 20012-20013 2 
20012-000001 20012-20013 3  
20012-000001 20012-20013 4   
20012-000001 20012-20013 5 
sqlSTR = "SELECT tblStudent.StudentID AS '??? ??????' , (tblStudent.FirstName + ' ' + tblStudent.MiddleName + ' ' + tblStudent.GrandFatherName + ' ' + tblStudent.LastName) as '?????' ," & _ 
       "tblStudent.Gender as '?????', tblStudent.Citizenship as '???????', tblStudent.Type as '??? ?????'," & _ 
       "tblDepartment.DepartmentTitle as '?????', tblEnrolment.SchoolYear as '????? ????????',tblYearLevel.YearLevelTitle as '????? ???????', " & _ 
       "'????'= CASE WHEN Len(tblGraduate.StudentID)<>12 THEN '???' ELSE ''End , " & _ 
       "'???? ???'= CASE WHEN Len(tblDropped.StudentID)<>12 THEN '???' ELSE ''End , " & _ 
       "'??????'= CASE WHEN tblStudent.Transferee ='True' THEN '???' ELSE ''End" & _ 
       " FROM tblDropped RIGHT JOIN " & _ 
       "(tblGraduate RIGHT JOIN " & _ 
       "(tblDepartment RIGHT JOIN " & _ 
       "(tblYearLevel RIGHT JOIN " & _ 
       "(tblSection RIGHT JOIN " & _ 
       "(tblStudent LEFT JOIN tblEnrolment " & _ 
       "ON tblStudent.StudentID = tblEnrolment.StudentID) " & _ 
       "ON tblSection.SectionID = tblEnrolment.SectionOfferingID) " & _ 
       "ON tblYearLevel.YearLevelID = tblEnrolment.YearLevelID) " & _ 
       "ON tblDepartment.DepartmentID = tblSection.DepartmentID) " & _ 
       "ON tblGraduate.StudentID = tblStudent.StudentID) " & _ 
       "ON tblDropped.StudentID = tblStudent.StudentID" & _ 
       " " & sFilter & _ 
       " ORDER BY tblStudent.StudentID DESC , tblYearLevel.YearLevelTitle ASC" 
+1

母親...... O_O(抱歉,無法抗拒) – fresskoma 2012-07-28 20:44:13

回答

0

添加日期字段由最近的包含記錄和過濾你的表。如果表中已經有一個包含按日期的WHERE子句?

如果我理解你的表正確的最後一個記錄總是在最後一個學期,如果你知道這個學期剛剛做了UNIQUE關鍵字進行查詢的student_id數據