MySql(四) 任务

项目7

统计各部门工资最高的员工

create table employee(
 id int not null,
 name varchar(32) not null,
 salary int not null,
 departmentid int not null
 );
insert into employee (id,name,salary,departmentid) values
 (1,'Joe',70000,1),
 (2,'Henry',80000,2),
 (3,'Sam',60000,2),
 (4,'Max',90000,1);
create table department(
 id int not null,
 name varchar(32) not null
 );
insert into department(id,name) values
 (1,'IT'),
 (2,'Sales');

select d.name as department, e.name, e.salary from empolyee e
 join (select max(salary) as salary from employee group b departmentid)
 as g on e.salary=g.salary
 left join department d on e.departmentid=d.id;

 

 

 

 

项目8

小美是一所中学的信息科技老师,她有一张 seat 座位表,平时用来储存学生名字和与他们相对应的座位 id。
其中纵列的 id 是连续递增的
小美想改变相邻俩学生的座位。
你能不能帮她写一个 SQL query 来输出小美想要的结果呢?
请创建如下所示 seat 表:
示例:
+---------+---------+
| id | student |
+---------+---------+
| 1 | Abbot |
| 2 | Doris |
| 3 | Emerson |
| 4 | Green |
| 5 | Jeames |
+---------+---------+
假如数据输入的是上表,则输出结果如下:
+---------+---------+
| id | student |
+---------+---------+
| 1 | Doris |
| 2 | Abbot |
| 3 | Green |
| 4 | Emerson |
| 5 | Jeames |
+---------+---------+

 

posted on 2019-04-06 21:19  NetDevOps  阅读(192)  评论(0编辑  收藏  举报

导航