当前位置:网站首页>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 ');
边栏推荐
- 国内数字藏品的乱象与未来
- STM32 operation w25q256 w25q16 SPI flash
- log4qt内存泄露问题,heob内存检测工具的使用
- 【MYSQL】-【子查询】
- Halcon installation and testing in vs2017, DLL configuration in vs2017
- Cs61abc sharing session (VI) detailed explanation of program input and output - standard input and output, file, device, EOF, command line parameters
- Go, how to become a gopher, and find work related to go language in 7 days, Part 1
- [summer daily question] Luogu p1601 a+b problem (high precision)
- Better performance and simpler lazy loading of intersectionobserverentry (observer)
- 佳木斯市场监管局开展防疫防虫害专题食品安全网络培训
猜你喜欢

Segger's hardware anomaly analysis

10 practical uses of NFT

零数科技深度参与信通院隐私计算金融场景标准制定

Mutationobserver document learning

佳木斯市场监管局开展防疫防虫害专题食品安全网络培训

Technology sharing | quick intercom integrated dispatching system

Monitor the bottom button of page scrolling position positioning (including the solution that page initialization positioning does not take effect on mouse sliding)

Go, how to become a gopher, and find work related to go language in 7 days, Part 1

LANDSCAPE

Excellent urban design ~ good! Design # visualization radio station will be broadcast soon
随机推荐
Use custom annotations to verify the size of the list
状态机dp三维
You study, I reward, 21 day learning challenge | waiting for you to fight
梳理市面上的2大NFT定价范式和4种解决方案
Amaze UI 图标查询
Dilworth 定理
【无标题】格式保存
Write some DP
FLink CDC 的mysql connector中,mysql的字段是varbinary, 官方
The difference between static library and dynamic library of program
监听页面滚动位置定位底部按钮(包含页面初始化定位不对鼠标滑动生效的解决方案)
新生代公链再攻「不可能三角」
SEGGER 的硬件异常 分析
【暑期每日一题】洛谷 P6461 [COCI2006-2007#5] TRIK
@Detailed explanation of requestmapping usage
Pat class a 1150 traveling salesman problem
flutter只要是数据,都会判空的
佳木斯市场监管局开展防疫防虫害专题食品安全网络培训
The new generation of public chain attacks the "Impossible Triangle"
Measured waveform of boot capacitor short circuit and open circuit of buck circuit