客户表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(转自)