当前位置:   article > 正文

经典SQL数据库面试题以及答案—Oracle版本-SQL全部在plsql开发编写-欢迎提问

plsql查询没有学全所有课的同学的学号姓名
  1. Student(Sno,Sname,Sage,Ssex) 学生表 S1:学号;Sname:学生姓名;Sage:学生年龄;Ssex:学生性别
  2. Course(Cno,Cname,T1) 课程表 C1,课程编号;Cname:课程名字;T1:教师编号
  3. SC(Sno,Cno,score) 成绩表 S1:学号;C1,课程编号;score:成绩
  4. Teacher(Tno,Tname) 教师表 T1:教师编号; Tname:教师名字
  5. --建表
  6. create table student(
  7. sno int primary key,
  8. sname varchar2(10) not null,
  9. sage int not null,
  10. sses char(1) ,
  11. constraint check_age check((sage)>0 and (sage)<120)
  12. );
  13. create table course(
  14. cno int primary key,
  15. cname varchar2(10) not null,
  16. tno int not null,
  17. constraint fk_course_teacher foreign key(tno) references teacher(tno)
  18. );
  19. create table teacher(
  20. tno int primary key,
  21. tname varchar2(10) not null
  22. );
  23. create table sc (
  24. sno int ,
  25. cno int ,
  26. score number,
  27. constraint fk_cno_sc foreign key (cno) references course(cno),
  28. constraint fk_cno_student foreign key (sno) references student(sno)
  29. );
  30. --修改表
  31. alter table student rename column sses to ssex;
  32. alter table student drop column ssex;
  33. alter table student add ( ssex varchar2(2)) ;
  34. --插数据
  35. insert into student values('001','zhang三',22,'男');
  36. insert into student values('002','wangwu2',22,'男');
  37. insert into student values('003','史蒂夫',23,'男');
  38. insert into student values('004','艾德',20,'女');
  39. insert into student values('005','猪八戒',32,'男');
  40. insert into student values(6,'合家福',12,'女');
  41. select * from student;
  42. insert into teacher values('1','徐大大');
  43. insert into teacher values('2','王富人');
  44. insert into teacher values('3','大大');
  45. insert into teacher values('5','李大大');
  46. insert into teacher values('6','陈大大');
  47. insert into teacher values('89','刘在石');
  48. insert into teacher values('9','何达大');
  49. insert into teacher values('10','彭建军');
  50. select * from teacher;
  51. insert into course values('1','Oracle数据','1');
  52. insert into course values('2','计算机原理','1');
  53. insert into course values('3','数据结构','3');
  54. insert into course values('4','算法概论','3');
  55. insert into course values('5','数据库原理','3');
  56. insert into course values('6','软件工程','6');
  57. insert into course values('7','UML','5');
  58. insert into course values('8','Java语言','89');
  59. insert into course values('9','嵌入式系统','10');
  60. select * from course order by cno desc;
  61. delete from sc s where rowid = (select rowid from sc where sno =3 and rownum =1 and cno =8);
  62. delete from sc s where rowid !=(select max(rowid) from sc b where s.cno=b.cno and b.cno =2)
  63. delete from sc s where cno =2;
  64. select rowid from sc where cno = 8;
  65. select cno,count(cno) from sc group by cno having count(cno) !=5 ;/2 4 3
  66. insert into sc(sno,cno,score) values(6,1,48);
  67. insert into sc(sno,cno,score) values(6,2,55);
  68. insert into sc(sno,cno,score) values(6,3,46);
  69. insert into sc(sno,cno,score) values(6,4,35);
  70. insert into sc(sno,cno,score) values(6,5,52);
  71. select * from sc where sno =6;
  72. select count(cno),cno from sc group by cno;
  73. select * from sc order by cno;
  74. select * from sc where cno =4 or cno =3 order by cno ,sno;
  75. select * from sc order by cno asc,sno asc,score desc;
  76. select s.sno,s.Sname,count(sc.sno),sum(sc.score) from student s
  77. left join sc on sc.sno = s.sno group by sc.sno ;
  78. --Question and Exercise
  79. 1、查询“001”课程比“002”课程成绩高的所有学生的学号;
  80. select a.sno from
  81. (select sno,score from sc where cno =1) a,
  82. (select sno,score from sc where cno =2) t
  83. where a.score >t.score and a.sno =t.sno;
  84. //sno=1 2 3 4 5
  85. select * from sc where sno =5
  86. 2、查询平均成绩大于60分的同学的学号和平均成绩;
  87. select sno,round(avg(score),1) from sc group by sno having avg(score)> 60;
  88. //round(数值,小数位数) Math.round()四舍五入取整原理:先+0.5 然后再向下取整(floor ),ceil
  89. //decimal()
  90. 3、查询所有同学的学号、姓名、选课数、总成绩;
  91. select s.sno,s.sname,count(c.rowid),sum(c.score) from student s ,sc c group by c.sno; 错误!!! 连接查询 和 分组
  92. select s.sno,s.sname,count(c.cno), sum(c.score) from student s left join sc c on s.sno = c.sno group by s.sno ,s.sname order by s.sno;
  93. select s.sno,s.sname,s.ssex,count(c.cno),sum(c.score) from student s,sc c where s.sno = c.sno(+) group by s.sno,s.sname,s.ssex;
  94. /*但是现在一旦分组之后,实际上对于语法上就会出现了新的限制,对于分组有以下要求:
  95. 1分组函数可以在没有分组的时候单独用使用,可是却不能出现其他的查询字段;
  96. 分组函数单独使用:
  97. SELECT COUNT(empno) FROM emp;
  98. 错误的使用,出现了其他字段:
  99. SELECT empno,COUNT(empno) FROM emp;
  100. 2如果现在要进行分组的话,则SELECT子句之后,只能出现分组的字段和统计函数,其他的字段不能出现:
  101. 正确做法:
  102. SELECT job,COUNT(empno),AVG(sal)
  103. FROM emp
  104. GROUP BY job;
  105. 错误的做法:
  106. SELECT deptno,job,COUNT(empno),AVG(sal)
  107. FROM emp
  108. GROUP BY job;
  109. */
  110. 4、查询姓“李”的老师的个数;
  111. select count(s.tno),s.tname from teacher s where s.tname like '李%' group by tname;
  112. 5、查询没学过“叶平”老师课的同学的学号、姓名;
  113. select * from teacher;
  114. insert into teacher values(66,'叶平');
  115. insert into course values(0,'C语言基础',66);
  116. insert into sc values(1,0,98)
  117. 嵌套
  118. select t.sno,t.sname from student t where not exists (
  119. select sno from sc where t.sno =sc.sno and cno in (
  120. select cno from course where tno in(
  121. select tno from teacher where tname='叶平'
  122. )));
  123. 内连接
  124. select t.sno,t.sname from student t where t.sno not in(
  125. select sno from sc s,course c,teacher b where
  126. s.cno = c.cno and
  127. c.tno = b.tno and
  128. b.tname = '叶平'
  129. );
  130. 6、查询学过“001”并且也学过编号“002”课程的同学的学号、姓名;
  131. //select * from sc
  132. //select s.sno 学号,sname 姓名 from student s,sc c where s.sno=c.sno(+) and c.cno =1 and c.cno =2;
  133. //select s.sno ,s.sname from student s left join sc c on s.sno = c.sno where c.cno between 1 and 2;
  134. select distinct s.sno , s.sname from student s ,sc c where s.sno = c.sno and c.cno between 1 and 2 group by s.sno,s.sname having count(s.sno)=2;
  135. //select s.sno , s.sname from student where s.sno in ()
  136. 7、查询学过“叶平”老师所教的所有课的同学的学号、姓名;
  137. select s.sno,s.sname from student s,sc c,course co ,teacher t
  138. where
  139. s.sno =c.sno and
  140. c.cno =co.cno and
  141. co.tno = t.tno and
  142. t.tname ='叶平';
  143. 8、查询课程编号“002”的成绩比课程编号“001”课程低的所有同学的学号、姓名;
  144. select sno,sname from student s where s.sno in(
  145. select a.sno from (select score,sno from sc where cno=1) a
  146. left join (select score,sno from sc where cno=2) b
  147. on a.sno = b.sno where a.score>b.score
  148. );
  149. update sc set score =99 where cno =2 and sno=1;
  150. select * from sc where cno between 1 and 2 ;
  151. 9、查询所有课程成绩小于60分的同学的学号、姓名;--没有一门成绩>60
  152. 采用 any some all 类的比较量词
  153. select distinct s.sno,sname from student s left join sc b on s.sno= b.sno where 60> all(select score from sc z where z.sno=b.sno);
  154. select s.sno,s.sname from student s where s.sno not in
  155. (select sno from sc b where b.score >60 and s.sno=b.sno);
  156. 10、查询没有学全所有课的同学的学号、姓名;
  157. select * from sc order by sno,cno,score;
  158. select s.sno,s.sname from student s where s.sno in (
  159. select sno from (select sno,count(rowid) from sc group by sno
  160. having count(rowid)<10 order by sc.sno asc)
  161. );
  162. select s.sno,s.sname from student s,sc b where
  163. s.sno = b.sno group by s.sno,s.sname having count(cno) < (select count(cno) from course);
  164. 11、查询至少有一门课与学号为“1001”的同学所学相同的同学的学号和姓名;
  165. select s.sno ,s.sname from student s where s.sno in
  166. (
  167. select sno from sc b where exists (select cno from sc c where sno =6 and b.cno =cno)
  168. )
  169. select distinct s.sno ,s.sname from student s,sc b where
  170. s.sno =b.sno and b.cno in (select cno from sc t where t.sno=6);
  171. 测试 一个没有跟sno=1相同学好的同学
  172. select * from sc where sno =6
  173. insert into student values(7,'刘备',23,'男')
  174. insert into sc values(7,9,'89')
  175. 12、查询至少学过学号为“001”同学所有一门课的其他同学学号和姓名;
  176. select distinct s.sno,s.sname from student s,sc b where s.sno = b.sno and b.cno in (select cno from sc where sno = 6);
  177. 13、把“SC”表中“叶平”老师教的课的成绩都更改为此课程的平均成绩;
  178. --oracle产生随机数
  179. select round(dbms_random.value(0,100),1) from dual;
  180. dbms_random.string (opt char, len NUMBER);
  181. --opt:表示返回值可能包含的东西
  182. ----'u','U' : 任何大写字母
  183. ----'l','L' : 任何小写字母
  184. ----'a','A' : 大小写混合字母
  185. ----'x','X' : 大写字母和数字混合
  186. ----'p','P' : 任何可打印字符
  187. ----其他参数 : 任何大写字母
  188. --len:表示要返回的字符串长度
  189. select dbms_random.string('x', 19) from dual
  190. begin
  191. for cr in (select rowid from sc )
  192. loop --循环
  193. update sc b set score =round(dbms_random.value(0,100),1) --更新语句(根据查询出来的结果集合)
  194. where rowid = b.rowid;
  195. end loop; --结束循环
  196. end;
  197. commit;
  198. /*sql循环更新模板
  199. BEGIN
  200. FOR L_RECORD IN (select id from customer_config where salt is null)
  201. LOOP
  202. UPDATE customer_config
  203. SET passwd=dbms_random.string('x',8)
  204. WHERE id=L_RECORD.id;
  205. END LOOP;
  206. commit;
  207. END;*/
  208. update sc so set score = (
  209. select distinct round(avg(score),1) from sc b where b.cno = (
  210. select distinct s.cno from sc s,course c,teacher t where s.cno = c.cno and c.tno = t.tno and t.tname = '叶平'
  211. )) where so.cno =
  212. ( select distinct s.cno from sc s,course c,teacher t where s.cno = c.cno and c.tno = t.tno and t.tname = '叶平')
  213. update sc s1 set score=(
  214. select avg(sc2.score) from sc s2 where s1.sno = s2.sno
  215. ) from sc sc2,course c,teacher t where sc2.cno =c.cno and t.tno = c.tno and t.tname ='叶平';
  216. insert into sc values(4,0,round(dbms_random.value(0,100),1));
  217. select * from sc b where b.cno = 0;
  218. 14、查询和“1002”号的同学学习的课程完全相同的其他同学学号和姓名;
  219. select * from sc order by sno,cno,score;
  220. select distinct s.sno,s.sname from student s,sc b where s.sno = b.sno and
  221. b.cno in(select cno from sc where sno = 1)
  222. 15、删除学习“叶平”老师课的SC表记录;
  223. select * from sc b,course c,teacher t where b.cno = c.cno and c.tno = t.tno and t.tname ='叶平';
  224. select * from sc where cno = 2;
  225. delete from sc b,course c,teacher t where b.cno = c.cno and c.tno =t.tno and t.tname = '叶平';
  226. select * from course c,teacher t where c.tno = t.tno and t.tname = '叶平';
  227. delete from sc b where b.sno in (select bb.sno from sc bb,course c,teacher t
  228. where b.cno = bb.cno and bb.cno= c.cno and c.tno = t.tno and t.tname ='叶平')
  229. 16、向SC表中插入一些记录,这些记录要求符合以下条件:没有上过编号“003”课程的同学学号、2
  230. 号课的平均成绩;
  231. begin
  232. for sn in(select distinct sno from sc b where b.sno not in (select sno from sc bb where bb.cno=3) )
  233. loop
  234. insert into sc values(sn.sno,2,(select round(avg(a.score),1) from sc a group by a.cno having a.cno = 2));
  235. end loop;
  236. end;
  237. insert into sc select s.sno,2,(select round(avg(score),1) from sc b where b.cno=2)
  238. from student s where s.sno not in (select sno from sc where cno =3)
  239. select * from sc where sno =7;
  240. 17、按平均成绩从高到低显示所有学生的“数据库”、“企业管理”、
  241. “英语”三门的课程成绩,按如下形式显示: 学生ID,数据库,企业管理,英语,有效课程数,有效平均分
  242. select sno,b.cno,(select cname from course c where cno =b.cno),count(*),avg(score)
  243. from sc b
  244. group by sno,cno
  245. select s1.sno 学生ID,
  246. (select b.score from sc b where b.cno =1 and b.sno =s1.sno) as 数据库,
  247. (select b.score from sc b where b.cno =8 and b.sno = s1.sno) Java,
  248. (select b.score from sc b where b.cno =3 and b.sno = s1.sno) 数据结构,
  249. count(*) 有效课程数,
  250. round(avg(score),1)有效平均分
  251. from sc s1
  252. group by s1.sno
  253. order by round(avg(score),1)
  254. 18、查询各科成绩最高和最低的分:以如下形式显示:课程ID,最高分,最低分
  255. select b.cno 课程ID,
  256. (select cname from course where b.cno = cno) 课程,
  257. max(score) 最高分,
  258. min(score) 最低分,
  259. round(avg(score),1) 平均分
  260. from sc b group by b.cno
  261. 19、按各科平均成绩从低到高和及格率的百分数从高到低顺序
  262. select b.cno 课程编号,
  263. (select cname from course where cno =b.cno) 课程名,
  264. round(avg(b.score),1) 平均分,
  265. concat(round(sum(case when b.score>60 then 1 else 0 end)/count(*)*100,1),'%') 及格率
  266. from sc b group by b.cno order by avg(b.score);
  267. --验证 cno 的及格率
  268. select sum(score) ,round(
  269. sum(
  270. case
  271. when b.score>=60
  272. then 1
  273. else 0
  274. end
  275. )/count(*),2) 及格率,count(*) from sc b where cno =2;
  276. select * from sc where cno = 2 3个及格的,共5个,及格率60%
  277. 20、查询如下课程平均成绩和及格率的百分数(用"1行"显示): 企业管理(001),马克思(002),OO&UML (003),数据库(004
  278. select b.cno 课程编号,
  279. (select cname from course where cno =b.cno) "课程名",
  280. round(avg(b.score),1) 平均分,
  281. concat(round(sum(case when b.score>60 then 1 else 0 end)/count(*)*100,1),'%') 及格率
  282. from sc b group by b.cno having b.cno in(1,2,3,4) order by avg(b.score);
  283. 21、查询不同老师所教不同课程平均分从高到低显示
  284. select t.tname, round(avg(s.score),1) from sc s,course c,teacher t
  285. where s.cno = c.cno and c.tno =t.tno
  286. group by t.tname;
  287. 22、查询如下课程成绩第 3 名到第 6 名的学生成绩单:企业管理(001),马克思(002),UML (003),数据库(004
  288. [学生ID],[学生姓名],企业管理,马克思,UML,数据库,平均成绩
  289. select * from(
  290. select rownum rn, s1.sno,s1.sname,c.cname,s.score from student s1,sc s,course c
  291. where rownum<=6 and c.cno =s.cno and s.cno=1 and s1.sno =s.sno
  292. group by rownum ,s1.sno,s1.sname,c.cname,s.score
  293. order by s.score desc ) t where t.rownum<=6 and t.rownum>=3
  294. select s.sname,round(avg(b.score),1) ,
  295. (select score from sc t where cno =1 and c.cno=t.sno ) 计算机原理,
  296. (select score from sc t where cno =3 and c.cno=t.sno ) 数据结构,
  297. (select score from sc t where cno =5 and c.cno=t.sno ) 数据库原理,
  298. (select score from sc t where cno =6 and c.cno=t.sno ) Java语言
  299. from student s,sc b,course c
  300. where s.sno = b.sno and b.cno = b.cno
  301. group by s.sname
  302. select * from course;
  303. 23、统计列印各科成绩,各分数段人数:课程ID,课程名称,[100-85],[85-70],[70-60],[ <60]
  304. select c.cno "课程编码",
  305. c.cname "课程名称",
  306. sum(case when s.score between 85 and 100 then 1 else 0 end) "100-85",--别名如果是数字开头的话,就要双引号
  307. sum(case when s.score between 70 and 85 then 1 else 0 end) "85-70",
  308. sum(case when s.score between 60 and 70 then 1 else 0 end) "70-60",
  309. sum(case when s.score <60 then 1 else 0 end) "<60 "
  310. from sc s,course c
  311. where s.cno = c.cno
  312. group by c.cno,c.cname;
  313. select * from sc where cno=6 and score between 85 and 100;--between 较小数 and 较大数
  314. update sc set score = 85 where sno =5 and cno =6;
  315. 24、查询学生平均成绩及其名次
  316. select
  317. s.sname 姓名,
  318. round(avg(t.score),1) 平均成绩
  319. from student s,sc t
  320. where s.sno = t.sno
  321. group by s.sname
  322. order by round(avg(t.score),1) desc
  323. 25、查询各科成绩前三名的记录:(不考虑成绩并列情况)
  324. select s.sno,s.sname ,
  325. ( select top 3 score from sc where sno = s.sno )
  326. from student s,sc t
  327. where t.cno = c.cno
  328. --使用 row_number() over(partition by order by ),rank(), derank();函数
  329. select * from (select sno,
  330. cno,
  331. score,
  332. row_number() over(partition by cno order by score desc) rn
  333. from sc s
  334. )
  335. where rn <= 3
  336. 26、查询每门课程被选修的学生数
  337. select cno,count(cno) from sc group by cno
  338. select * from sc where cno = 1;
  339. 27、查询出只选修了一门课程的全部学生的学号和姓名
  340. 28、查询男生、女生人数
  341. select (select count(*) from student where ssex='女') 男生数, (select count(*) from student where ssex='男') 女生数 from dual;
  342. select * from student;
  343. 29、查询姓“张”的学生名单
  344. select * from student t where t.sname like '张%';
  345. 30、查询同名同性学生名单,并统计同名人数
  346. select s.*,count(*) from student s (select * from student) a where s.sname =a.sanme
  347. select sname,count(*) from student s group by s.sname having count(*)>1;
  348. 311981年出生的学生名单(注:Student表中Sage列的类型是datetime)
  349. select * from student where sage between to_date('1981-01-01','yyyy-mm-dd') and to_date('1981-12-31','yyyy-mm-dd');
  350. select Sname, CONVERT(char (11),DATEPART(year,Sage)) as age
  351. from student
  352. where CONVERT(char(11),DATEPART(year,Sage))='1981';
  353. 32、查询每门课程的平均成绩,结果按平均成绩升序排列,平均成绩相同时,按课程号降序排列
  354. select s.cno ,t.cname ,round( avg(s.score),1)
  355. from sc s,course t
  356. where s.cno = t.cno
  357. group by s.cno,t.cname
  358. order by round( avg(s.score),1) asc,cno desc
  359. select avg(score) from sc where cno =7
  360. 33、查询平均成绩大于85的所有学生的学号、姓名和平均成绩
  361. select s.sno 学号,s.sname 姓名,round(avg(t.score),1) 平均成绩
  362. from student s,sc t
  363. where s.sno = t.sno
  364. group by s.sno,s.sname
  365. having round(avg(t.score),1)>60;
  366. 34、查询课程名称为“数据库”,且分数低于60的学生姓名和分数
  367. select s.sname,t.score
  368. from student s,sc t,course c
  369. where
  370. s.sno =t.sno
  371. and t.cno = c.cno
  372. and c.cname like '%数据库%'
  373. and t.score <60;
  374. select * from course;
  375. 35、查询所有学生的选课情况;
  376. select s.sno,s.sname,t.cname
  377. from student s,course t,sc c
  378. where s.sno = c.sno and c.cno = t.cno
  379. order by sno
  380. 36、查询任何一门课程成绩在70分以上的姓名、课程名称和分数;
  381. select s.sname,c.cname,t.score
  382. from student s,sc t,course c
  383. where s.sno =t.sno
  384. and t.cno = c.cno
  385. and exists (select * from sc a where t.score >70 and a.sno= t.sno)
  386. 37、查询不及格的课程,并按课程号从大到小排列
  387. select distinct t.cno, c.cname
  388. from sc t,course c
  389. where t.cno = c.cno
  390. and t.score <60
  391. order by t.cno;
  392. 38、查询课程编号为003且课程成绩在80分以上的学生的学号和姓名;
  393. select s.sno,s.sname from student s,sc t
  394. where s.sno = t.sno
  395. and t.cno = 3
  396. group by s.sno,s.sname
  397. having min(t.score)>80;
  398. select * from sc where cno =3
  399. and not exists ( select * from sc a where a.score <80 and a.sno = s.sno)
  400. select * from sc t where not exists( select * from sc t where t.score <80)
  401. 39、求选了课程的学生人数
  402. select count(*) from sc where
  403. 40、查询选修“叶平”老师所授课程的学生中,成绩最高的学生姓名及其成绩
  404. select s.sname,a.score
  405. from sc a,course c,student s,teacher t
  406. where a.sno = s.sno
  407. and a.cno = c.cno
  408. and t.tno = c.tno
  409. and t.tname like '叶平'
  410. and a.score =(select max(score) from sc where cno = a.cno)
  411. group by s.sname;
  412. select * from teacher
  413. select * from teacher where tname='叶平'
  414. select * from sc where cno =1
  415. select * from course where tno =1;
  416. select * from sc a,teacher t,student s
  417. where a.sno = s.sno
  418. and t.no = a.cno
  419. and t.tname ='叶平'
  420. 41、查询各个课程及相应的选修人数
  421. select c.cname,t.cno,count(*) from sc t,course c
  422. where c.cno = t.cno
  423. group by c.cname,t.cno
  424. 42、查询不同课程成绩相同的学生的学号、课程号、学生成绩
  425. select s.sno,a.cno, a.score,b.score from sc a,sc b,student s
  426. where a.score= b.score
  427. and a.cno <>b.cno and a.sno = s.sno
  428. 43、查询每门功成绩最好的前两名
  429. --!!
  430. --如果不考虑分数重复,用RANK()
  431. select m.学号 , m.课程号 , m.成绩 from
  432. (
  433. select t.* , RANK() over(partition by 课程号 order by 成绩 desc) px from aa t
  434. ) m
  435. where px <= 2
  436. order by m.课程号 , m.成绩 desc
  437. select * from
  438. (
  439. select t.*,rank() over(partition by t.cno order by score desc) px from sc t
  440. ) m
  441. where px<=2
  442. order by m.cno,m.score desc
  443. --如果考虑分数重复,用DENSE_RANK()
  444. select m.学号 , m.课程号 , m.成绩 from
  445. (
  446. select t.* , DENSE_RANK() over(partition by 课程号 order by 成绩 desc) px from aa t
  447. ) m
  448. where px <= 2
  449. order by m.课程号 , m.成绩 desc
  450. select m.* from
  451. (
  452. select t.*,RANK() over(partition by t.cno order by t.score desc) px from sc t
  453. )m
  454. where px <=2
  455. order by
  456. 44、统计每门课程的学生选修人数(超过10人的课程才统计)。要求输出课程号和选修人数,查询结果按人数降序排列,查询结果按人数降序排列,若人数相同,按课程号升序排列
  457. select t.cno,count(t.sno)
  458. from sc t
  459. /*where count(t.sno)>10*/
  460. group by t.cno
  461. having count(t.sno)>10
  462. order by count(t.sno) desc,t.cno asc
  463. select t.cno,count(cno) from sc t group by t.cno order by cno
  464. select * from sc where cno = 5
  465. 45、检索至少选修两门课程的学生学号
  466. select sno
  467. from sc
  468. group by sno
  469. having count(cno)>2
  470. select * from sc where sno = 7
  471. 46、查询全部学生都选修的课程的课程号和课程名
  472. select *
  473. from course c
  474. where c.cno in (select cno from sc group by cno)
  475. 47、查询没学过“叶平”老师讲授的任一门课程的学生姓名
  476. select Sname from Student where Sno not in (select Sno from Course,Teacher,SC where Course.Tno=Teacher.Tno and SC.Cno=course.Cno and Tname='叶平');
  477. 48、查询两门以上不及格课程的同学的学号及其平均成绩
  478. select sno,avg(nvl(score,0)) from SC where sno in (select sno from SC where score <60 group by sno having count(*)>2)group by sno;
  479. 49、检索“004”课程分数小于60,按分数降序排列的同学学号
  480. select sno from SC where cno='004'and score <60 order by score desc;
  481. 50、删除“002”同学的“001”课程的成绩
  482. delete from Sc where S#='002'and C#='001';
  483. --sysdba 登录
  484. grant select on v$statname to scott;
  485. grant select on v$sesstat to scott;
  486. grant select on v$mystat to scott;
  487. grant select on v$mystat to scott;

数据库面试必知必会
[https://segmentfault.com/a/1190000013517914?utm_source=channel-hottest]https://segmentfault.com/a/1190000013517914?utm_source=channel-hottest

转载于:https://www.cnblogs.com/humi/p/7569587.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/365286
推荐阅读
相关标签
  

闽ICP备14008679号