标签:顺序 企业 数据分析 www uml 管理 显示 src case when
select t.sid as ‘学生ID‘,
(select score from sc where sid=t.sid and cid=‘002‘) as ‘语文‘,
(select score from sc where sid=t.sid and cid=‘003‘) as ‘数学‘,
(select score from sc where sid=t.sid and cid=‘004‘) as ‘英语‘,
count(t.cid) as ‘有效课程数‘,
avg(t.score) as ‘有效平均分‘
from sc t
group by t.sid
order by avg(t.score);
select cid as ‘课程ID‘,max(score) as ‘最高分‘,min(score) as ‘最低分‘
from sc group by cid order by cid;
select sc.cid,c.cname,round(IFNULL(avg(sc.score),0),2) as ‘平均成绩‘,
round(100*sum(case when ifnull(sc.score,0)>=60 then 1 else 0 end)/count(*),2) as ‘及格率‘
from sc sc,course c
where sc.cid=c.cid
group by 1,2
order by ‘及格率‘ desc;
select
sum(case when cid=‘002‘ then score else 0 end)/sum(case when cid=‘002‘ then 1 else 0 end) as ‘企业管理平均分‘,
sum(case when cid=‘002‘ and score>=60 then 1 else 0 end)/sum(case when cid=‘002‘ then 1 else 0 end) as ‘企业管理及格率‘,
sum(case when cid=‘003‘ then score else 0 end)/sum(case when cid=‘003‘ then 1 else 0 end) as ‘OO&UML平均分‘,
sum(case when cid=‘003‘ and score>=60 then 1 else 0 end)/sum(case when cid=‘003‘ then 1 else 0 end) as ‘OO&UML及格率‘,
sum(case when cid=‘004‘ then score else 0 end)/sum(case when cid=‘004‘ then 1 else 0 end) as ‘数据库平均分‘,
sum(case when cid=‘004‘ and score>=60 then 1 else 0 end)/sum(case when cid=‘004‘ then 1 else 0 end) as ‘数据库及格率‘
from sc;
select c.cid,max(c.cname) as ‘cname‘,max(t.tid) as ‘tid‘,max(t.tname) as ‘tname‘,
avg(score) as ‘avgscore‘
from sc sc,course c,teacher t
where sc.cid=c.cid and c.tid=t.tid
group by c.cid
order by avgscore desc;
select sc.cid,max(c.cname) as ‘课程名称‘,
sum(case when sc.score between 85 and 100 then 1 else 0 end) as ‘[100-85]‘,
sum(case when sc.score between 70 and 85 then 1 else 0 end) as ‘[85-70]‘,
sum(case when sc.score between 60 and 70 then 1 else 0 end) as ‘[70-60]‘,
sum(case when sc.score between 0 and 100 then 1 else 0 end) as ‘[ <60]‘
from sc sc,course c
where sc.cid=c.cid
group by sc.cid
select s.Sid,s.Sname,T2.AvgScore,
(select COUNT(AvgScore) from
(select Sid,AVG(Score) as ‘AvgScore‘ from SC group by Sid) as T1
where T2.AvgScore<T1.AvgScore)+1 as ‘Rank‘
from
(select Sid,AVG(Score) as ‘AvgScore‘ from SC
group by Sid) as T2,
Student s
where s.Sid=T2.Sid
order by AvgScore desc
select sc.cid,c.cname,sc.sid,s.sname,sc.score
from student s,sc sc,course c
where sc.cid=c.cid and sc.sid=s.sid and sc.score in
(
select score from sc sc2
where sc.cid=sc2.cid
order by score desc
)
order by sc.cid,sc.Score desc
select sc.cid,max(c.cname) as ‘CNAME‘,count(distinct sc.sid) as ‘studentCount‘
from sc sc,course c
where sc.cid=c.cid
group by sc.cid;
select s.sid,s.sname
from student s
where s.sid in
(select sc.sid from sc sc
group by sc.sid
having count(distinct sc.cid)=3)
select COUNT(sid) as ‘BoysCount‘ from Student s where s.Ssex=‘男‘;
select COUNT(sid) as ‘GirlsCount‘ from Student s where s.Ssex=‘女‘
select s.sid,s.Sname
from Student s
where s.Sname like ‘张%‘
select s.Sname,COUNT(Sname) as ‘SameCount‘
from Student s
group by s.Sname
having COUNT(Sname)>1
select sc.cid,AVG(sc.Score) as ‘AvgScore‘
from SC sc
group by sc.cid
order by AvgScore asc,cid desc
select sc.sid,s.Sname,AVG(sc.Score) as ‘AvgScore‘
from Student s,SC sc
where s.sid=sc.sid
group by sc.sid,s.Sname
having AVG(sc.Score)>85
select s.Sname,sc.Score from Student s,SC sc,Course c
where s.Sid=sc.Sid and sc.Cid=c.Cid and c.Cname=‘数学‘ and sc.Score<60
select s.Sid,s.Sname,c.Cid,c.Cname from Student s,SC sc,Course c
where s.Sid=sc.Sid and c.Cid=sc.Cid
order by s.Sid
select distinct s.sid,s.sname,c.cname,sc.score
from student s,sc sc,course c
where s.sid=sc.sid and sc.cid=c.cid and sc.score>=70;
select distinct sc.cid,c.cname from sc sc,course c
where sc.cid=c.cid and sc.score<60
order by sc.cid desc;
select sc.sid,s.sname,sc.score
from student s,sc sc
where s.sid=sc.sid and sc.cid=‘003‘ and sc.score>=80;
select count(distinct sid) as ‘studentCount‘ from sc;
select s.sid,s.sname,sc.score
from student s,sc sc,course c,teacher t
where s.sid=sc.sid and sc.cid=c.cid and c.tid=t.tid and t.tname=‘杨艳‘
and sc.score=
(
select max(sc2.score) from sc sc2 where sc.cid=sc2.cid
)
文章转载自https://www.cnblogs.com/edisonchou/p/3878135.html
欢迎加入数据分析交流群(加群备注博客园)
标签:顺序 企业 数据分析 www uml 管理 显示 src case when
原文地址:https://www.cnblogs.com/linxiaochi/p/9650356.html