SQL编程学习06

这篇博客主要介绍了SQL编程的学习练习,包括各部门工资最高的员工、换座位、分数排名等题目的解决。还讨论了如何优化练习题目,如行转列、列转行的转换,以及连续登录天数问题的解决思路。提出了对习题设置的建议,如创建通用表格、同类题目归组及考虑更多实际场景。
摘要由CSDN通过智能技术生成

第一组练习:

1. 各部门工资最高的员工
create table employee 
(
	emp_id char(4) not null,
    emp_name varchar(100) not null,
    salary integer default 0,
    department_id char(4) not null,
    primary key (emp_id)
);

create table department
(
	dep_id char(4) not null,
    dep_name varchar(100) not null,
    primary key (dep_id)
)
;

insert into employee values ('1','Joe','70000','1');
insert into employee values ('2','Henry','80000','2');
insert into employee values ('3','Sam','60000','2');
insert into employee values ('4','Max','90000','1');

insert into department values ('1','IT');
insert into department values ('2','Sales');

select department_id, emp_name, salary
from 
(
	select department_id, emp_name, salary
			,rank() over (partition by d.dep_id order by e.salary desc) as rank_num 
	from employee e
	left join department d
	on e.department_id = d.dep_id
)a1
where rank_num = 1
;
2. 换座位
create table seat
(
	seat_id char(4) not null,
    stu_name varchar(100) not null
)
;

insert into seat values ('1','Abbot'),('2','Doris'),('3','Emerson'),('4','Green'),('5','Jeames');

3. 分数排名
create table score
(
	score_id char(4) not null,
    scores char(4)
)
;
insert into score values ('1','3.50'),('2','3.65'),('3','4.00'),('4','3.85'),('5','4.00'),('6','3.65');

select *
	,dense_rank() over (order by scores desc) as rank_num
from score
;

5. 树节点
create table tree
(
	cur_id char(4) 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值