1、同一个服务器跨数据库查询
selecta列1,a列2,b列1,b列1,from数据1dob查询表1ainnerJoin数据2dbo查询表2b
onb关联字段=a关联字段
where条件
2、不同服务跨数据库查询:
首先创建链接服务器,后查询方法与1类似,只是查询时需要把数据链接名称添加到查询中。
具体 *** 作参看:blogcsdnnet/htl258/article/details/5695391
Student 学生表
Course 课程表
SC 成绩表
Teacher 教师表
问题:
1、查询“001”课程比“002”课程成绩高的所有学生的学号;
selectaS# froma, b
where ascorebscore and as#=bs#;
2、查询平均成绩大于60分的同学的学号和平均成绩;
selectS#,avg
from sc
group by S# having avg 60;
3、查询所有同学的学号、姓名、选课数、总成绩;
selectStudentS#,StudentSname,count,sum
from Student left Outer join SC on StudentS#=SCS#
group by StudentS#,Sname
4、查询姓“李”的老师的个数;
selectcount)
from Teacher
where Tname like ‘李%‘;
5、查询没学过“叶平”老师课的同学的学号、姓名;
selectStudentS#,StudentSname
from Student
where S# not infrom SC,Course,Teacher where SCC#=CourseC# and TeacherT#=CourseT# and TeacherTname=‘叶平‘);
6、查询学过“001”并且也学过编号“002”课程的同学的学号、姓名;
selectStudentS#,StudentSname from Student,SC where StudentS#=SCS# and SCC#=‘001‘and exists;
7、查询学过“叶平”老师所教的所有课的同学的学号、姓名;
selectS#,Sname
from Student
where S# in = from Course,Teacher where TeacherT#=CourseT# and Tname=‘叶平‘));
8、查询课程编号“002”的成绩比课程编号“001”课程低的所有同学的学号、姓名;
selectS#,Sname fromscore2
from Student,SC where StudentS#=SCS# and C#=‘001‘) S_2 where score2 score;
9、查询所有课程成绩小于60分的同学的学号、姓名;
selectS#,Sname
from Student
where S# not in ;
10、查询没有学全所有课的同学的学号、姓名;
selectStudentS#,StudentSname
from Student,SC
where StudentS#=SCS# group by StudentS#,StudentSname having count from Course);
以上就是关于SQL数据库跨库查询语句怎么写(数据库跨表查询语句)全部的内容,包括:SQL数据库跨库查询语句怎么写(数据库跨表查询语句)、sql2005数据库查询语句、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)