我使用的asp.net2.0分页控件,如果使用了distinct数据显示在gv中是1条,但是地下的总记录数显示是6, 而且还有一个问题。如下:select distinct Count(pj.ProjectID) from OLTR_ExamTestPaper as etp inner join OLTR_StudyStudentRCourse as rc on etp.CourseID=rc.CourseID inner join OLTR_StudySubjectRCourse as src on etp.CourseID=src.CourseID inner join OLTR_StudyProjectRSubject as rs on src.SubjectID=rs.SubjectID inner join OLTR_StudyProject as pj on rs.ProjectID=pj.ProjectID and etp.PaperAgain=1 and (StartTime <= getdate() and getdate() <= Endtime ) where rc.tag<>1 and rc.CourseID not in(select distinct pr.CourseID from OLTR_ExamPaperRecard as pr) and rc.StudentID='S08030012' and rs.ProjectID='P08120001'我想要得到count()的值.我想得到1 ,却出来6 ,如何是好a 加distinct也不行!!!!????????
在使用join時候的注意點: 如果只要使用join的表中某個或幾個字段,就不要join整個表!!!!select distinct Count(pj.ProjectID) from OLTR_ExamTestPaper as etp inner join (select distinct CourseID from OLTR_StudyStudentRCourse) as rc on etp.CourseID=rc.CourseID inner join (select distinct CourseID from OLTR_StudySubjectRCourse) as src on etp.CourseID=src.CourseID inner join (select distinct subjectid from OLTR_StudyProjectRSubject) as rs on src.SubjectID=rs.SubjectID inner join (select distinct ProjectID from OLTR_StudyProject as pj on rs.ProjectID=pj.ProjectID and etp.PaperAgain=1 and (StartTime <= getdate() and getdate() <= Endtime ) where rc.tag<>1 and rc.CourseID not in(select distinct pr.CourseID from OLTR_ExamPaperRecard as pr) and rc.StudentID='S08030012' and rs.ProjectID='P08120001'
你加上distinct不就得了吗
而且还有一个问题。如下:select distinct Count(pj.ProjectID) from OLTR_ExamTestPaper as etp
inner join OLTR_StudyStudentRCourse as rc on etp.CourseID=rc.CourseID
inner join OLTR_StudySubjectRCourse as src on etp.CourseID=src.CourseID
inner join OLTR_StudyProjectRSubject as rs on src.SubjectID=rs.SubjectID
inner join OLTR_StudyProject as pj on rs.ProjectID=pj.ProjectID and etp.PaperAgain=1
and (StartTime <= getdate() and getdate() <= Endtime )
where rc.tag<>1 and rc.CourseID not in(select distinct pr.CourseID
from OLTR_ExamPaperRecard as pr) and rc.StudentID='S08030012' and rs.ProjectID='P08120001'我想要得到count()的值.我想得到1 ,却出来6 ,如何是好a 加distinct也不行!!!!????????
如果只要使用join的表中某個或幾個字段,就不要join整個表!!!!select distinct Count(pj.ProjectID) from OLTR_ExamTestPaper as etp
inner join (select distinct CourseID from OLTR_StudyStudentRCourse) as rc on etp.CourseID=rc.CourseID
inner join (select distinct CourseID from OLTR_StudySubjectRCourse) as src on etp.CourseID=src.CourseID
inner join (select distinct subjectid from OLTR_StudyProjectRSubject) as rs on src.SubjectID=rs.SubjectID
inner join (select distinct ProjectID from OLTR_StudyProject as pj on rs.ProjectID=pj.ProjectID and etp.PaperAgain=1
and (StartTime <= getdate() and getdate() <= Endtime )
where rc.tag<>1 and rc.CourseID not in(select distinct pr.CourseID
from OLTR_ExamPaperRecard as pr) and rc.StudentID='S08030012' and rs.ProjectID='P08120001'
C# 里用tables[i].rows.count