mysql数据库面试题学生表_SQL笔试题:下面是学生表(student)的结构说明
SQL筆試題:下面是學生表(student)的結構說明字段名稱字段解釋字段類型字段長度約束
s_id學號字符10PK
s_name學生姓名字符50Not?null
s_age學生年齡數(shù)值3Not?null
s-sex學生性別字符(男:1女:0)1Not?null
下面是教師表(Teacher?)的結構說明字段名稱字段解釋字段類型字段長度約束
t_id教師編號字符10PK
t_name教師名字字符50Not?null
下面是課程表(Course)的結構說明字段名稱字段解釋字段類型字段長度約束
c_id課程編號字符10PK
c_name課程名字字符50Not?null
t_id教師編號字符10Not?null
下面是成績表(SC)的結構說明字段名稱字段解釋字段類型字段長度約束
s_id學號字符10PK
c_id課程編號字符10Not?null
score成績數(shù)值3Not?null
1、查詢“001”課程比“002”課程成績高的所有學生的學號;
select a.s_id from (select s_id,score from SC where C_ID='001') a,(select s_id,score
from SC where C_ID='002') b
where a.score>b.score and a.s_id=b.s_id;
2、查詢平均成績大于60分的同學的學號和平均成績;
select S_ID,avg(score)
from sc
group by S_ID having avg(score) >60;
3、查詢所有同學的學號、姓名、選課數(shù)、總成績;
select Student.S_ID,Student.Sname,count(SC.C_ID),sum(score)
from Student left Outer join SC on Student.S_ID=SC.S_ID
group by Student.S_ID,Sname
4、查詢姓“李”的老師的個數(shù);
select count(distinct(Tname))
from Teacher
where Tname like '李%';
5、查詢沒學過“葉平”老師課的同學的學號、姓名;
select Student.S_ID,Student.Sname
from Student
where S_ID not in (select distinct( SC.S_ID) from SC,Course,Teacher where SC.C_ID=Course.C_ID and Teacher.T#=Course.T# and Teacher.Tname='葉平');
6、查詢學過“001”并且也學過編號“002”課程的同學的學號、姓名;
elect Student.S_ID,Student.Sname from Student,SC where Student.S_ID=SC.S_ID and SC.C_ID='001'and exists( Select * from SC as SC_2 where SC_2.S_ID=SC.S_ID and SC_2.C_ID='002');
7、查詢學過“葉平”老師所教的所有課的同學的學號、姓名;
select S_ID,Sname
from Student
where S_ID in (select S_ID from SC ,Course ,Teacher where SC.C_ID=Course.C_ID and Teacher.T#=Course.T# and Teacher.Tname='葉平' group by S_ID having count(SC.C_ID)=(select count(C_ID) from Course,Teacher where Teacher.T#=Course.T# and Tname='葉平'));
8、查詢課程編號“002”的成績比課程編號“001”課程低的所有同學的學號、姓名;
Select S_ID,Sname from (select Student.S_ID,Student.Sname,score ,(select score from SC SC_2 where SC_2.S_ID=Student.S_ID and SC_2.C_ID='002') score2
from Student,SC where Student.S_ID=SC.S_ID and C_ID='001') S_2 where score2 < score;
9、查詢所有課程成績小于60分的同學的學號、姓名;
select S_ID,Sname
from Student
where S_ID not in (select S.S_ID from Student AS S,SC where S.S_ID=SC.S_ID and score>60);
10、查詢沒有學全所有課的同學的學號、姓名;
select Student.S_ID,Student.Sname
from Student,SC
where Student.S_ID=SC.S_ID group by Student.S_ID,Student.Sname having count(C_ID)
11、查詢至少有一門課與學號為“1001”的同學所學相同的同學的學號和姓名;
select distinct S_ID,Sname from Student,SC where?Student.S_ID=SC.S_ID and SC.C_ID in (select C_ID from SC where S_ID='1001');
12、查詢至少學過學號為“001”同學所有一門課的其他同學學號和姓名;
select distinct SC.S_ID,Sname
from Student,SC
where Student.S_ID=SC.S_ID and C_ID in (select C_ID from SC where S_ID='001');
總結
以上是生活随笔為你收集整理的mysql数据库面试题学生表_SQL笔试题:下面是学生表(student)的结构说明的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MoveAbsJ在使用时和MOVEJ有什
- 下一篇: 3道常见的SQL笔试题,你要不要来试试!