1学生表student
s#学号,sname姓名,difdate日期,班级grade
2课程表 course
c#课程号 ,名字cname
3成绩单score
s#学号 c#课程号 成绩score
–1统计每个班级有多少人
select grade,count(sname) from ze_student group by grade;
–2、2007级的各学生的平均成绩 没有成绩的为0;
select a.sname,(select avg(nvl(b.score,0)) from ze_score b where b.s#=a.s#) from ze_student a where grade=2007;
–3 每科 平均成绩和最高成绩 最低成绩 2007级 保留2位小数点 四舍五入
select b.c#,avg(b.score),max(b.score),min(nvl(b.score,0)) from ze_student a,ze_score b where b.s# = a.s# and a.grade =2007 group by b.c#;
–4 给2007级 数学加5分
update ze_score
set score=nvl(score,0)+5
where s# in (select s# from ze_student where grade=2007) and c# =(select c# from ze_course where cname=’数学’);
–5 90分以上的为优秀 90到85为良好,60分 不及格 各人平均成绩
select s#, c,
case
when c>=90 then ‘优秀’
when c<90 and c>=60 then ‘及格’
else ‘不及格’ end as jige
from (select s#,avg(nvl(score,0)) as c from ze_score group by s# ) order by jige desc;
–6 求同月出生的 人数
select to_char(difdate,’mm’) as 月份,count(s#) as 出生人数 from ze_student group by to_char(difdate,’mm’);
–7 各科的及格率和平均成绩 截取 保留2位
–及格率
select c#,avg(nvl(score,0))as 平均成绩,sum(nvl(score,0))as 总成绩, count(s#) as 各科人数,
trunc(sum(
case when nvl(score,0)>60 then ‘1’
else ‘0’ end)/count(s#),2) as 及格率
from ze_score group by c#;
–每人的及格率
select s#, avg(nvl(score,0))as 平均成绩,sum(nvl(score,0))as 总成绩, count(c#) as 总科目,
sum(
case when nvl(score,0)>60 then 1
else 0 end
)/count(c#) as 及格率
from ze_score group by s#;
–8删除 姓名是张三 的大学语文 成绩
select * from ze_score where s# in (select s# from ze_student where sname in ‘张三’) and c#=(select c# from ze_course where cname =’大学语文’);
–9 将数学替换成高等数学
update ze_course set cname=’高等数学’where cname like ‘%数学%’;
–10 格式化 ,显示 将学号修改成s开头 不足12位补0;
–查询
select concat(‘s’,lpad(s#,11,0)) as s# from ze_score ;
select concat(‘s’,lpad(s#,11,0)) as s# from ze_student ;
–格式化
update ze_score set s#= concat(‘s’,lpad(s#,9,0));
update ze_student set s#= concat(‘s’,lpad(s#,9,0));
四个足球队
select a.name,b.name from qiu a,qiu b where a.name<b.name;
commit
rollback
服务器类型
服务器协议
全局数据库名称
服务器ip地址
服务器端口号
用户名和密码