资源描述:
《sql经典面试题》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、usetest/*问题及描述:--1.学生表Student(S#,Sname,Sage,Ssex)--S#学生编号,Sname学生姓名,Sage出生年月,Ssex学生性别--2.课程表Course(C#,Cname,T#)--C#--课程编号,Cname课程名称,T#教师编号--3.教师表Teacher(T#,Tname)--T#教师编号,Tname教师姓名--4.成绩表SC(S#,C#,score)--S#学生编号,C#课程编号,score分数select*fromStudentselect*fromCourseselect
2、*fromTeacherselect*fromSC*/--创建测试数据createtableStudent(S#varchar(10),Snamenvarchar(10),Sagedatetime,Ssexnvarchar(10))insertintoStudentvalues('01',N'赵雷','1990-01-01',N'男')insertintoStudentvalues('02',N'钱电','1990-12-21',N'男')insertintoStudentvalues('03',N'孙风','1990-05-
3、20',N'男')insertintoStudentvalues('04',N'李云','1990-08-06',N'男')insertintoStudentvalues('05',N'周梅','1991-12-01',N'女')insertintoStudentvalues('06',N'吴兰','1992-03-01',N'女')insertintoStudentvalues('07',N'郑竹','1989-07-01',N'女')insertintoStudentvalues('08',N'王菊','1990-01-2
4、0',N'女')createtableCourse(C#varchar(10),Cnamenvarchar(10),T#varchar(10))insertintoCoursevalues('01',N'语文','02')insertintoCoursevalues('02',N'数学','01')insertintoCoursevalues('03',N'英语','03')createtableTeacher(T#varchar(10),Tnamenvarchar(10))insertintoTeachervalues('0
5、1',N'张三')insertintoTeachervalues('02',N'李四')insertintoTeachervalues('03',N'王五')createtableSC(S#varchar(10),C#varchar(10),scoredecimal(18,1))insertintoSCvalues('01','01',80)insertintoSCvalues('01','02',90)insertintoSCvalues('01','03',99)insertintoSCvalues('02','01',7
6、0)insertintoSCvalues('02','02',60)insertintoSCvalues('02','03',80)insertintoSCvalues('03','01',80)insertintoSCvalues('03','02',80)insertintoSCvalues('03','03',80)insertintoSCvalues('04','01',50)insertintoSCvalues('04','02',30)insertintoSCvalues('04','03',20)insertin
7、toSCvalues('05','01',76)insertintoSCvalues('05','02',87)insertintoSCvalues('06','01',31)insertintoSCvalues('06','03',34)insertintoSCvalues('07','02',89)insertintoSCvalues('07','03',98)go--1、查询"01"课程比"02"课程成绩高的学生的信息及课程分数--1.1、查询同时存在"01"课程和"02"课程的情况selecta.*,b.score[课
8、程'01'的分数],c.score[课程'02'的分数]fromStudenta,SCb,SCcwherea.S#=b.S#anda.S#=c.S#andb.C#='01'andc.C#='02'andb.score>c.score--1.2、查询同时存在"01"课程和"02