码迷,mamicode.com
首页 > 数据库 > 详细

MySql(四) 任务

时间:2019-04-06 21:35:50      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:rtm   ble   color   font   varchar   sel   null   style   sql   

项目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;

 

MySql(四) 任务

标签:rtm   ble   color   font   varchar   sel   null   style   sql   

原文地址:https://www.cnblogs.com/marathoner/p/10662936.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!