Oracle(SQL查询测试题)

本文详细介绍了使用SQL进行复杂查询的方法,包括如何获取客户的最新登录时间及已购物记录,以及如何计算并找出超过班级平均成绩的学生信息。这些技巧对于数据库管理和数据分析人员来说非常实用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

--客户表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;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值