一公司的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); 
 

 

http://www.it130.cn/Article/FAQ/shujuku/Oracle/2007-7-13/200707132320350.html(转自)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值