电脑技术网——专业手机电脑知识平台,关注科技、手机、电脑、智能硬件
MySQLMSSQLAccessOracle

sql 语句练球与答案

2020-01-28 21:21:18 出处:[ 菜菜电脑网 ] 人气:次阅读
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地址
服务器端口号
用户名和密码

关于我们 - 广告合作 - 联系我们 - 免责声明 - 网站地图 - 投诉建议 - 在线投稿

©CopyRight 2008-2020 caicaipc.com Inc All Rights Reserved.
菜菜电脑网 版权所有