1

这是我的查询,它两次显示具有相同信息的数据。我应该怎么做,它只会显示一次数据?

    SELECT 
        STUDENT.Stud_Num, STUDENT.Last_Name, STUDENT.First_Name, 
        STUDENT.Middle_Name, STUDENT.Program, CORRELATION.Corr_Code, 
        AVERAGE.Remarks, ACAD_QTR_LINK.Acad_Year, ACAD_QTR_LINK.Qtr, 
        COURSE.Course_Name, GRADES.Grades, GRADES.[No.OfTakes] 
    FROM 
        STUDENT
inner join 
        AVERAGE on STUDENT.Stud_Num = AVERAGE.Stud_Num 
inner join 
        CORRELATION on AVERAGE.Corr_Code = CORRELATION.Corr_Code 
inner join 
        ACAD_QTR_LINK on AVERAGE.Acad_Qtr_ID = ACAD_QTR_LINK.Acad_Qtr_ID 
inner join 
        CORR_COUR_LINK on STUDENT.Stud_Num = CORR_COUR_LINK.Stud_Num 
inner join 
        COURSE on CORR_COUR_LINK.Course_Code = COURSE.Course_Code 
inner join 
        GRADES on CORR_COUR_LINK.Corr_Cour_ID = GRADES.Corr_Cour_ID 
where 
        STUDENT.Stud_Num like '%' and STUDENT.Program like '%' 
        and STUDENT.Last_Name like '%' and STUDENT.First_Name like '%' 
        and STUDENT.Middle_Name like '%' and ACAD_QTR_LINK.Acad_Year like '%' 
        and ACAD_QTR_LINK.Qtr like '%' 
        and COURSE.Course_Name like '%' and CORRELATION.Corr_Code like '%' 

结果输出:

|StudNum|LName|FName|MName|Prog|CorrCode|Remarks|AcadYr|Qtr|CorName|Grades|No.OfTakes
|2007131|Mendo|charisn|Chucka|ECE|ece12345|7.00000|  '11-'12 |3rd|Mathema|89.000| 1
|2007131|Mendo|charisn|Chucka|ECE|ece12345|7.00000|  '11-'12 |3rd|Mathema|89.000| 1
|2007131|Mendo|charisn|Chucka|ECE|ece12345|7.00000|  '11-'12 |3rd|Electroni|65.000| 1
|2007131|Mendo|charisn|Chucka|ECE|ece12345|7.00000|  '11-'12 |3rd|Electroni|65.000| 1
4

1 回答 1

0

响应 1 如果行完全相同,请添加不同的,或者您可以按所有列分组。

SELECT distinct STUDENT.Stud_Num, ....

如果您还可以找出使联接返回多行的表,或者引入其他条件来限制它们,这也可能消除重复的行。

看到您的评论后回复2 。

SELECT STUDENT.Stud_Num, STUDENT.Last_Name, STUDENT.First_Name, STUDENT.Middle_Name, STUDENT.Program, CORRELATION.Corr_Code, 
AVERAGE.Remarks, ACAD_QTR_LINK.Acad_Year, ACAD_QTR_LINK.Qtr, 
COURSE.Course_Name, GRADES.Grades, GRADES.[No.OfTakes] FROM STUDENT
inner join AVERAGE on STUDENT.Stud_Num = AVERAGE.Stud_Num 
inner join CORRELATION on AVERAGE.Corr_Code = CORRELATION.Corr_Code 
inner join ACAD_QTR_LINK on AVERAGE.Acad_Qtr_ID = ACAD_QTR_LINK.Acad_Qtr_ID 
inner join CORR_COUR_LINK on STUDENT.Stud_Num = CORR_COUR_LINK.Stud_Num 
inner join COURSE on CORR_COUR_LINK.Course_Code = COURSE.Course_Code 
inner join GRADES on CORR_COUR_LINK.Corr_Cour_ID = GRADES.Corr_Cour_ID 
where STUDENT.Stud_Num like '%' and STUDENT.Program like '%' 
and STUDENT.Last_Name like '%' and STUDENT.First_Name like '%' 
and STUDENT.Middle_Name like '%' and ACAD_QTR_LINK.Acad_Year like '%' 
and ACAD_QTR_LINK.Qtr like '%' 
and COURSE.Course_Name like '%' and CORRELATION.Corr_Code like '%' 
group by STUDENT.Stud_Num, STUDENT.Last_Name, STUDENT.First_Name, STUDENT.Middle_Name, STUDENT.Program, CORRELATION.Corr_Code, 
AVERAGE.Remarks, ACAD_QTR_LINK.Acad_Year, ACAD_QTR_LINK.Qtr, 
COURSE.Course_Name, GRADES.Grades, GRADES.[No.OfTakes]

工作小提琴 - http://sqlfiddle.com/#!3/2f42e/5

于 2013-03-13T02:50:21.617 回答