当前位置:网站首页>Phased learning about the entry-level application of SQL Server statements - necessary for job hunting (I)
Phased learning about the entry-level application of SQL Server statements - necessary for job hunting (I)
2022-07-29 07:46:00 【lz_ N_ one】
First stage exercise
*************** This chapter is suitable for non basic learners or those who have a certain foundation but do not have a solid grasp of knowledge ******************************
The following exercises are performed according to the tables initialized into the database , Please be sure to execute the following table creation statement first .
create table s1_student( sno varchar2(10) primary key, sname varchar2(30), sbirthday varchar2(30), ssex varchar2(10),sclass varchar2(10) );
create table s1_teacher( tno varchar2(10) primary key, tname varchar2(30),tsex varchar2(10),tbirthday varchar2(30),prof varchar2(30),depart varchar2(30) );
create table s1_course( cno varchar2(10), cname varchar2(30), tno varchar2(10) );
create table s1_score( sno varchar2(10), cno varchar2(10), degree number );
create table s1_grade( low number, upp number, rank varchar2(2) );
*/ Initialize student table s1_student/
insert into s1_student values ('108', ' Zeng Hua ', '1997/9/1', ' male ', '95033');
insert into s1_student values ('105', ' Kuang Ming ', '1995/10/2', ' male ', '95031');
insert into s1_student values ('107', ' Wang Li ', '1996/1/23', ' Woman ', '95033');
insert into s1_student values ('101', ' Li Jun ', '1996/2/20', ' male ', '95033');
insert into s1_student values ('109', ' Wang Fang ', '1995/2/10', ' Woman ', '95031');
insert into s1_student values ('103', ' Lu Jun ', '1994/6/3', ' male ', '95031');
commit;
/ Initialize the teacher table s1_teacher/
insert into s1_teacher values ('804', ' Li Cheng ',' male ','1979-12-2',' associate professor ',' Department of Computer Science ');
insert into s1_teacher values ('856', ' Zhang Xu ',' male ','1985-3-12',' lecturer ',' Department of electronic engineering ');
insert into s1_teacher values ('825', ' Wang Ping ',' Woman ','1989-5-2',' Assistant ',' Department of Computer Science ');
insert into s1_teacher values ('831', ' Liu Bing ',' Woman ','1988-8-2',' Assistant ',' Department of electronic engineering ');
commit;
/******* first
Initial Curriculum s1_course********/
insert into s1_course values ('3-105', ' Introduction to computer ', '825');
insert into s1_course values ('3-245', ' operating system ', '804');
insert into s1_course values ('6-166', ' Data circuits ', '856');
insert into s1_course values ('9-888', ' Advanced mathematics ', '800');
commit;
/ Initialize the grade sheet s1_score*/
insert into s1_score values ('103', '3-245', 86);
insert into s1_score values ('105', '3-245', 75);
insert into s1_score values ('109', '3-245', 68);
insert into s1_score values ('103', '3-105', 92);
insert into s1_score values ('105', '3-105', 88);
insert into s1_score values ('109', '3-105', 76);
insert into s1_score values ('101', '3-105', 64);
insert into s1_score values ('107', '3-105', 91);
insert into s1_score values ('108', '3-105', 78);
insert into s1_score values ('101', '6-166', 85);
insert into s1_score values ('107', '6-106', 79);
insert into s1_score values ('108', '6-166', 81);
commit;
/ Initialize the grade classification table s1_grade*/
insert into s1_grade values ('90', '100', 'A');
insert into s1_grade values ('80', '89', 'B');
insert into s1_grade values ('70', '79', 'C');
insert into s1_grade values ('60', '69', 'D');
insert into s1_grade values ('0', '59', 'E');
commit;
1. Inquire about s1_student All the records in the table Sname、Ssex and Class Column .
select sname,ssex,sclass from s1_student;
2. Query all the units of the teacher is not repeated Depart Column .
select distinct depart from s1_teacher;
3. Inquire about s1_student All the records of the table .
select * from s1_student;
4. Inquire about s1_score The score in the table is 60 To 80 All records between .
select * from s1_score where degree between 60 and 80;
5. Inquire about s1_score The score in the table is 85,86 or 88 The record of .
select * from s1_score where degree in (85,86,88);
6. Inquire about s1_student In the table “95031” Class or gender is “ Woman ” Of the students .
select * from s1_student where sclass='95031' or ssex=' Woman ';
7. With Class Descending query s1_student All the records of the table .
select * from s1_student order by sclass desc;
8. With Cno Ascending 、Degree Descending query s1_score All the records of the table .
select * from s1_score order by cno,degree desc;
9. Inquire about “95031” The number of students in the class .
select count(sno) from s1_student where sclass='95031';
10. Inquire about s1_score The student number and course number with the highest score in the table .
select sno,cno from s1_score where degree =(select max(degree) from s1_score);
11. Inquire about ‘3-105’ The average score of course No .
select avg(degree) from s1_score where cno='3-105';
12. Inquire about s1_score There is at least 5 Three students took the course and took 3 The average score of the first course .
select cno,avg(degree) from s1_score where cno like '3%' group by cno having count(sno)>5;
13. The minimum query score is greater than 70, The highest score is less than 90 Of Sno Column .
select sno from s1_score group by sno having min(degree)>70 and max(degree)<90;
14. Look up all the students Sname、Cno and Degree Column .
select sname,cno ,degree from s1_student st,s1_score sc where st.sno=sc.sno(+);
15. Look up all the students Sno、Cname and Degree Column .
select sno,cname,degree from s1_score sc,s1_course co where sc.cno(+)=co.cno;
16. Look up all the students Sname、Cname and Degree Column .
select sname,cname,degree from s1_student st,s1_score sc,s1_course co where st.sno=sc.sno(+) and sc.cno=co.cno(+);
17. Inquire about “95033” The average score of the course chosen by the class .
select avg(degree) from s1_score sc,s1_student st where st.sno=sc.sno and sclass='95033';
18. Now I want to check all the students Sno、Cno and rank Column .
select sno,cno,degree,(select rank from s1_grade where low<=degree and upp>=degree)as rank from s1_score;
19. Check options “3-105” The grade of the course is higher than “109” The records of all the students in the grade of No .
(1)select * from s1_score where cno='3-105' and degree >(select degree from s1_score where cno='3-105' and sno='109');
(2)select x.CNO ,x.SNO ,x.DEGREE from s1_score x,s1_score y
where x.CNO ='3-105' and x.DEGREE >y.DEGREE and y.SNO ='109'and y.CNO='3-105';
20. Inquire about s1_score The record that the score of students who choose to study more than one course is not the highest score .
select * from s1_score j where j.SNO in (
select SNO from s1_score group by SNO having count(*)>=2) and
j.DEGREE <(select max(DEGREE)from s1_score b where b.CNO = j.CNO );
21. The inquiry result is higher than the student number “109”、 The course number is “3-105” All records of the results of .
select * from s1_score where degree>(select degree from s1_score where sno='109'and cno='3-105') and cno='3-105';
22. The inquiry and student ID are 108 Of all students born in the same year Sno、Sname and Sbirthday Column .
select sno,sname,sbirthday from s1_student st1 where substr(sbirthday,1,4)in (select substr(sbirthday,1,4) from s1_student where sno='101');
23. Inquire about “ Zhang Xu “ The results of the students who teach .
select sc.* from s1_score sc,s1_teacher th,s1_course co where sc.cno=co.cno and co.tno=th.tno and th.tname=' Zhang Xu ';
24. The number of students taking a course is more than 5 The teacher's name .
(1)select tname from s1_teacher th,s1_course co where th.tno=co.tno and co.cno in (select cno from s1_score group by cno having count(sno)>5);
(2)select TNAME from s1_teacher where TNO in(
select x.TNO from s1_course x inner join s1_score y on x.CNO =y.CNO
group by x.TNO having count(x.TNO )>5);
25. Inquire about 95033 Class and 95031 A record of all the students in the class .
select * from s1_student where sclass in('95033','95031');
26. There are 85 A course with a score of above Cno.
select cno from s1_score group by cno having max(degree)>=85;
27. Query out “ Department of Computer Science “ The teacher's score sheet for the course .
select sc.* from s1_score sc,s1_teacher th,s1_course co where sc.cno=co.cno and co.tno=th.tno and th.depart=' Department of Computer Science ';
28. Inquire about “ Department of Computer Science ” And “ Department of electronic engineering “ Teachers with different titles Tname and Prof.
select TNAME,PROF from s1_teacher where DEPART =' Department of Computer Science ' and PROF not in(
select PROF from s1_teacher where DEPART =' Department of electronic engineering ');
29. The number of the elective course is “3-105“ The course and the score shall be at least higher than the elective number “3-245” Of my classmates Cno、Sno and Degree, And press Degree Order from high to low .
(1)select sno,cno,degree from s1_score where cno='3-105' and degree >(
select min(degree) from s1_score where cno='3-245')order by degree desc;
(2)select * from s1_score where CNO ='3-105' and DEGREE >any (
select DEGREE from s1_score where CNO ='3-245')order by DEGREE desc;
30. The number of the elective course is “3-105” And the score is higher than the elective number “3-245” Of the class Cno、Sno and Degree.
(1)select sno,cno,degree from s1_score where cno='3-105' and degree >(
select max(degree) from s1_score where cno='3-245')order by degree desc;
(2)select * from s1_score where CNO ='3-105' and DEGREE >all(
select DEGREE from s1_score where CNO ='3-245');
31. Check all the teachers and students name、sex and birthday.
select sname as name,ssex as sex from s1_student
union all
select tname as name,tsex as sex from s1_teacher;
32. Query all “ Woman ” Teachers and “ Woman ” Classmate name、sex and birthday.
select sname as name,ssex as sex,sbirthday as birthday from s1_student where ssex=' Woman '
union all
select tname as name,tsex as sex,tbirthday as birthday from s1_teacher where tsex=' Woman ';
33. Look up the grade table of the students whose grades are lower than the average of the course .
(1)select sc1.* from s1_score sc1,(select cno,avg(degree)as degree from s1_score group by cno) sc2 where sc1.cno=sc2.cno and sc1.degree<sc2.degree;
(2)select * from s1_score a where DEGREE <(
select avg(DEGREE) from s1_score b where a.CNO=b.CNO);
34. Look up all the teachers Tname and Depart.
(1)select tname,depart from s1_teacher th,s1_course co where th.tno=co.tno;
(2)select TNAME,DEPART from s1_teacher where exists
(select * from s1_course where s1_course.TNO = s1_teacher.TNO );
35. Look up all the teachers who didn't give lectures Tname and Depart.
(1)select tname,depart from s1_teacher th where th.tno not in (
select tno from s1_course);
(2)select tname,depart from s1_teacher th where not exists (
select tno from s1_course co where th.tno=co.tno);
36. At least there are 2 Class number of three boys .
select sclass from s1_student where ssex=' male ' group by sclass having count(sno)>=2;
37. Inquire about s1_student There is no surname in the table “ king ” Of the students .
select * from s1_student where sname not like ' king %';
38. Inquire about s1_student The name and age of each student in the table .
select sname,to_char(sysdate,'yyyy')-substr(sbirthday,1,4) as tage from s1_student;
39. Inquire about s1_student The largest and smallest of the tables Sbirthday Date value .
select max(sbirthday),min(sbirthday) from s1_student;
40. Search by shift number and age from big to small s1_student All the records in the table .
select * from s1_student order by sclass desc,sbirthday asc;
41. Inquire about “ male ” Teachers and their courses .
select th.tno,th.tname,th.tsex,co.cno from s1_teacher th,s1_course co where th.tno=co.tno and th.tsex=' male ';
42. Look up the students with the highest scores Sno、Cno and Degree Column .
select * from s1_score where degree =(select max(degree) from s1_score);
43. Query and “ Li Jun ” All other classmates of the same sex Sname.
select sname from s1_student where ssex =(select ssex from s1_student where sname=' Li Jun ') and sname<>' Li Jun ';
44. Query and “ Li Jun ” Same sex classmates Sname.
(1)select sname from s1_student st1 where exists
(select * from s1_student st2 where st2.sname=' Li Jun ' and st1.sclass=st2.sclass and st1.ssex=st2.ssex);
(2)select SNAME from s1_student where SSEX =(select SSEX from s1_student where SNAME =' Li Jun ') and SCLASS =(select SCLASS from s1_student where SNAME =' Li Jun ');
45. Check all electives “ Introduction to computer ” Curriculum “ male ” Student's score sheet
(1)select sc.* from s1_score sc,s1_course co,s1_student st
where sc.sno=st.sno and sc.cno=co.cno and co.cname=' Introduction to computer ' and st.ssex=' male ';
(2)select * from s1_score where SNO in(select SNO from s1_STUDENT where SSEX =' male ')
and CNO =(select CNO from s1_COURSE where CNAME =' Introduction to computer ');
边栏推荐
- 【暑期每日一题】洛谷 P6320 [COCI2006-2007#4] SIBICE
- [WPF] realize language switching through dynamic / static resources
- MapReduce steps of each stage
- 零数科技深度参与信通院隐私计算金融场景标准制定
- Jianmu continuous integration platform v2.5.2 release
- @JsonSerialize注解的使用
- Cross domain problems when downloading webapi interface files
- [summer daily question] Luogu p7760 [coci2016-2017 5] tuna
- Better performance and simpler lazy loading of intersectionobserverentry (observer)
- Zero technology is deeply involved in the development of privacy computing financial scenario standards of the ICT Institute
猜你喜欢

新生代公链再攻「不可能三角」

Analyze the roadmap of 25 major DFI protocols and predict the seven major trends in the future of DFI

Mutationobserver document learning

207. Curriculum

LANDSCAPE
![[MySQL] - [subquery]](/img/81/0880f798f0f41724fd485ae82d142d.png)
[MySQL] - [subquery]

监听页面滚动位置定位底部按钮(包含页面初始化定位不对鼠标滑动生效的解决方案)
黑盒测试常见错误类型说明及解决方法有哪些?

10 practical uses of NFT

Jump from mapper interface to mapping file XML in idea
随机推荐
Credit card shopping points
You study, I reward, 21 day learning challenge | waiting for you to fight
技术分享| 快对讲综合调度系统
写点dp
Amaze UI icon query
Realize the effect of changing some colors of a paragraph of text
cs61abc分享会(六)程序的输入输出详解 - 标准输入输出,文件,设备,EOF,命令行参数
postman接口测试|js脚本之阻塞休眠和非阻塞休眠
Dilworth theorem
[summer daily question] Luogu P6500 [coci2010-2011 3] zbroj
Multi thread shopping
MySQL uses date_ FORMAT(date,'%Y-%m')
How can electronic component trading enterprises solve warehouse management problems with ERP system?
State machine DP (simple version)
In JS, 0 means false, and non-0 means true
Dilworth 定理
Go 事,如何成为一个Gopher ,并在7天找到 Go 语言相关工作,第1篇
功能自动化测试实施的原则以及方法有哪些?
Can the subset of the array accumulate K
【暑期每日一题】洛谷 P6500 [COCI2010-2011#3] ZBROJ