--客户表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
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);
create view emp11
as
select * from emp;
select *from (select * from (select * from emp where sal is not null )order by sal desc )where rownum<=3;
-- 不断调试,不断实验
update emp set sal=1111 where empno=7839;
--1.求每个客户的最新登陆时间time,姓名name,客户id?
--2.查最新登陆并且已经购买商品的客户id,name,登陆的时间time(一条sql语句)
--一个表student中有班级classid,学号id,成绩grade
--1.计算各个班的平均成绩
--2.查找比该班平均成绩高的学生的班级classid,学号id,成绩grade
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);
create view emp11
as
select * from emp;
select *from (select * from (select * from emp where sal is not null )order by sal desc )where rownum<=3;
-- 不断调试,不断实验
update emp set sal=1111 where empno=7839;