1. 程式人生 > >一公司的oracle sql面試題

一公司的oracle sql面試題

客戶表a(id name address) 登陸流水錶b(id time) 購物流水錶c(id time productid productnum)
1.求每個客戶的最新登陸時間time,姓名name,客戶id?
2.查最新登陸並且已經購買商品的客戶id,name,登陸的時間time(一條sql語句)


一個表student中有班級classid,學號id,成績grade
1.計算各個班的平均成績
2.查詢比該班平均成績高的學生的班級classid,學號id,成績grade

----------------------------------------------------------------------

分析函式ok


--------------------------------------------------------

1.求每個客戶的最新登陸時間time,姓名name,客戶id
select a.id,a.name,d.time as time 
from a left join (select id,max(time) as time from b group by id) d
on a.id =d.id ;

2.查最新登陸並且已經購買商品的客戶id,name,登陸的時間time(一條sql語句)
select a.id,a.name,d.time as time 
from a,(select id,max(time) as time from b group by id) d
where a.id =d.id 
and exists (select * from c where id = a.id);

1.計算各個班的平均成績
select classid,avg(grade)
from student
group by classid;

2.查詢比該班平均成績高的學生的班級classid,學號id,成績grade
select a.classid,a.id,a.grade 
from student a 
where a.grade > (select avg(grade) from student where classid = a.classid);