如何在SQL Server 2008中为多个连接编写单个查询(给出示例查询)

时间:2015-06-30 21:36:55

标签: sql-server sql-server-2008 sql-server-2008-r2 sql-server-2012

我需要为多名学生重复下面的连接。如何优化并将其作为单个查询编写?

select * from percentage perct
join subject subj ON perct.subject_id=subj.subject_id
join student std ON subj.student_id = std.sutdent_id
Where std.student_name="xyz" and std.location="abc" and age="18"

select * from percentage perct
join subject subj ON perct.subject_id=subj.subject_id
join student std ON subj.student_id = std.sutdent_id
Where std.student_name="ccc" and std.location="kkk" and age="19"

1 个答案:

答案 0 :(得分:0)

select * from percentage perct
join subject subj ON perct.subject_id=subj.subject_id
join student std ON subj.student_id = std.sutdent_id
Where (std.student_name="xyz" and std.location="abc" and age="18")
or (std.student_name="ccc" and std.location="kkk" and age="19")