1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
| select sno,score from sc where cno='c001' and score<80 order by score desc
select c.cno,c.cname,count(sc.sno) 选修人数 from course c left join sc on c.cno=sc.cno group by c.cno,c.cname order by c.cno
select tno,listagg(cname,',')within group(order by cno) from course group by tno
select cno 课程ID, max(score) 最高分, min(score) 最低分 from sc group by cno order by cno
select sc.*,case when score>=60 then '是' else '否' end 是否及格 from sc
select sno,sname from student s where (select count(*) from sc where sc.sno=s.sno)=1 order by s.sno
select s.sno,s.sname,avg(score) from student s join sc on(s.sno=sc.sno) group by s.sno,s.sname having avg(score)>85 order by s.sno
select c.cno, c.cname, count(case when sc.score between 85 and 100 then 1 end) a, count(case when sc.score between 70 and 84 then 1 end) b, count(case when sc.score between 60 and 69 then 1 end) c, count(case when sc.score < 60 then 1 end) as d from sc join course c on sc.cno=c.cno group by c.cno, c.cname order by c.cno
select s.sname, sc.score from student s join sc on sc.sno=s.sno join course c on c.cno=sc.cno where c.cname='Oracle' and sc.score<60
select s.sno,s.sname, listagg(c.cname,'、')within group(order by sc.cno) 选课, count(sc.cno) 合计 from student s join sc on sc.sno=s.sno join course c on c.cno=sc.cno group by s.sno,s.sname
select cno,count(sno) 选修人数 from sc group by cno order by 选修人数 desc, cno
insert into sc(sno,cno,score) select s.sno,'c002',(select avg(score) from sc where cno='c002') from student s where s.sno not in ( select sno from sc where cno='c002' )
select c.cno,c.cname from course c where not exists( select 1 from student s where not exists( select 1 from sc where sc.sno=s.sno and sc.cno=c.cno ) )
select sno,sname from student s where exists( select 1 from course c where not exists( select 1 from sc where sc.sno=s.sno and sc.cno=c.cno ) )
select sc1.sno,sc1.score,sc2.score from sc sc1 join sc sc2 on sc1.sno=sc2.sno where sc1.cno='c001' and sc2.cno='c002' and sc1.score>sc2.score
update sc set score = 60 where cno='c001' and score<( select avg(score) from sc where cno='c001' )
delete from sc where cno in( select c.cno from course c join teacher t on c.tno=t.tno where t.tname='谌燕' )
create table dept1 as select * from scott.dept; insert into dept1 select * from scott.dept;
delete from dept1 where rowid not in( select max(rowid) from dept1 group by deptno )
delete from dept1 where rowid not in( select rowid from( select dept1.*,rowid,row_number()over(partition by deptno order by deptno) r from dept1 ) where r=1 )
select sno,sname from student s where not exists( select 1 from sc join course c on sc.cno=c.cno join teacher t on c.tno=t.tno where sc.sno=s.sno and t.tname='谌燕' ) order by s.sno
select sno,sname from student s where exists( select 1 from sc where sc.sno=s.sno and cno='c001' ) and exists( select 1 from sc where sc.sno=s.sno and cno='c002' ) order by s.sno
select sc.cno,s.sname,sc.score from sc join student s on s.sno=sc.sno where sc.score=( select max(score) from sc where cno=sc.cno ) order by sc.cno
with rnk as( select sc.cno 课程编号, s.sname 学生姓名, sc.score 学生成绩, dense_rank()over(partition by sc.cno order by sc.score desc) 排名 from sc join student s on s.sno=sc.sno ) select 课程编号,学生姓名,学生成绩 from rnk where 排名=1 order by 课程编号
with cy_c as( select c.cno from course c join teacher t on t.tno=c.tno where t.tname='谌燕' ), top_s as( select sname 学生姓名, score 成绩 ,dense_rank()over(order by sc.score desc) 排名 from sc join student s on s.sno=sc.sno where sc.cno in(select cno from cy_c) ) select 学生姓名,成绩 from top_s where 排名=1
with cy_c as( select c.cno from course c join teacher t on t.tno=c.tno where t.tname='谌燕' ) select s.sno 学号, s.sname 姓名 from student s where not exists( select 1 from cy_c where not exists( select 1 from sc where sc.sno=s.sno and sc.cno=cy_c.cno ) ) order by 学号
with s1_c as( select cno from sc where sno='s001' ) select s.sno,s.sname from student s join sc on sc.sno=s.sno where sc.cno in(select * from s1_c)
with s1_c as( select cno from sc where sno='s001' ) select s.sno 学号, s.sname 姓名 from student s join sc on sc.sno=s.sno where s.sno!='s001' and not exists( select 1 from s1_c where not exists( select 1 from sc where sc.sno=s.sno and sc.cno=s1_c.cno ) ) and not exists( select 1 from sc where sc.sno=s.sno and not exists( select 1 from s1_c where s1_c.cno=sc.cno ) ) order by s.sno
|