15-成績2

 
 
create table score(
name string,
chinese string,
math string
)
row format delimited fields terminated by ','
lines terminated by '\n'
stored as textfile;
load data local inpath '/score.txt' into table score;

create table class(
name string,
cname string
)
row format delimited fields terminated by ','
lines terminated by '\n'
stored as textfile;
load data local inpath '/class.txt' into table class;

數學最高分的學生所在班級的平均成績?
1.求出數學的最高分
2.根據最高分求出這個學生
3.根據學生查詢班級
4.根據班級查詢學生
5.根據學生查詢出成績
6.根據成績查詢平均值
select avg(s.math)
from
class c,score s,
(select c.cname
from class c,score s,
(select max(math) max from score)t
where s.math = t.max and s.name = c.name)t1
where t1.cname=c.cname and c.name = s.name


1.數學和語文平均成績均大於60分的班級和平均成績

數學成績大於60分的班級
select t1.math,t2.chinese,t1.cname
from
(select avg(math) math,cname
from score s join class c on s.name = c.name
group by cname having avg(math)>60) t1
join
(select avg(chinese) chinese,cname
from score s join class c on s.name = c.name
group by cname having avg(chinese)>60)t2
on 
t1.cname = t2.cname
語文大於60分的班級

select c.cname,avg(s.math),avg(s.chinese)
from
class c,score1 s
where c.name = s.name
group by c.cname
having avg(s.math)>60 and avg(s.chinese)>60


2.
查詢語文成績大於60
數學成績大於60

select t1.cname,t1.math,t2.chinese from
(select avg(s.math) as math,c.cname
from class c,score1 s
where c.name = s.name
group by c.cname
having avg(s.math)>60)t1
join
(select avg(s.chinese) as chinese,c.cname
from class c,score1 s
where c.name = s.name
group by c.cname
having avg(s.chinese)>60)t2
where t1.cname = t2.cname;

數據java

banzhang,89,98
tuanzhishu,99,89
xiaoming,55,66
xiaohong,88,66
xiaolong,55,66
xiaoliang,88,99
xiaoming,c1
xiaohei,c2
banzhang,c3
tuanzhishu,c2
xiaohong,c1
xiaolong,c2
xiaoliang,c3

  

相關文章
相關標籤/搜索