zoukankan      html  css  js  c++  java
  • 11.24

    一、题目描述

    查找所有员工的last_name和first_name以及对应的dept_name,也包括暂时没有分配部门的员工
    CREATE TABLE `departments` (
    `dept_no` char(4) NOT NULL,
    `dept_name` varchar(40) NOT NULL,
    PRIMARY KEY (`dept_no`));
    CREATE TABLE `dept_emp` (
    `emp_no` int(11) NOT NULL,
    `dept_no` char(4) NOT NULL,
    `from_date` date NOT NULL,
    `to_date` date NOT NULL,
    PRIMARY KEY (`emp_no`,`dept_no`));
    CREATE TABLE `employees` (
    `emp_no` int(11) NOT NULL,
    `birth_date` date NOT NULL,
    `first_name` varchar(14) NOT NULL,
    `last_name` varchar(16) NOT NULL,
    `gender` char(1) NOT NULL,
    `hire_date` date NOT NULL,
    PRIMARY KEY (`emp_no`));
     
    如插入:
    INSERT INTO departments VALUES('d001','Marketing');
    INSERT INTO departments VALUES('d002','Finance');
    INSERT INTO departments VALUES('d003','Human Resources');
    INSERT INTO departments VALUES('d004','Production');
    INSERT INTO departments VALUES('d005','Development');
    INSERT INTO departments VALUES('d006','Quality Management');

    INSERT INTO dept_emp VALUES(10001,'d001','1986-06-26','9999-01-01');
    INSERT INTO dept_emp VALUES(10002,'d001','1996-08-03','9999-01-01');
    INSERT INTO dept_emp VALUES(10003,'d004','1995-12-03','9999-01-01');
    INSERT INTO dept_emp VALUES(10004,'d004','1986-12-01','9999-01-01');
    INSERT INTO dept_emp VALUES(10005,'d003','1989-09-12','9999-01-01');
    INSERT INTO dept_emp VALUES(10006,'d002','1990-08-05','9999-01-01');
    INSERT INTO dept_emp VALUES(10007,'d005','1989-02-10','9999-01-01');
    INSERT INTO dept_emp VALUES(10008,'d005','1998-03-11','2000-07-31');
    INSERT INTO dept_emp VALUES(10009,'d006','1985-02-18','9999-01-01');
    INSERT INTO dept_emp VALUES(10010,'d005','1996-11-24','2000-06-26');
    INSERT INTO dept_emp VALUES(10010,'d006','2000-06-26','9999-01-01');

    INSERT INTO employees VALUES(10001,'1953-09-02','Georgi','Facello','M','1986-06-26');
    INSERT INTO employees VALUES(10002,'1964-06-02','Bezalel','Simmel','F','1985-11-21');
    INSERT INTO employees VALUES(10003,'1959-12-03','Parto','Bamford','M','1986-08-28');
    INSERT INTO employees VALUES(10004,'1954-05-01','Chirstian','Koblick','M','1986-12-01');
    INSERT INTO employees VALUES(10005,'1955-01-21','Kyoichi','Maliniak','M','1989-09-12');
    INSERT INTO employees VALUES(10006,'1953-04-20','Anneke','Preusig','F','1989-06-02');
    INSERT INTO employees VALUES(10007,'1957-05-23','Tzvetan','Zielinski','F','1989-02-10');
    INSERT INTO employees VALUES(10008,'1958-02-19','Saniya','Kalloufi','M','1994-09-15');
    INSERT INTO employees VALUES(10009,'1952-04-19','Sumant','Peac','F','1985-02-18');
    INSERT INTO employees VALUES(10010,'1963-06-01','Duangkaew','Piveteau','F','1989-08-24');
    INSERT INTO employees VALUES(10011,'1953-11-07','Mary','Sluis','F','1990-01-22');

    答案

    select last_name,first_name,dept_name from employees 
    left outer join dept_emp on employees.emp_no=dept_emp.emp_no
    left outer join departments on dept_emp.dept_no=departments.dept_no

    二、题目描述

    查找员工编号emp_no为10001其自入职以来的薪水salary涨幅(总共涨了多少)growth(可能有多次涨薪,没有降薪)
    CREATE TABLE `salaries` (
    `emp_no` int(11) NOT NULL,
    `salary` int(11) NOT NULL,
    `from_date` date NOT NULL,
    `to_date` date NOT NULL,
    PRIMARY KEY (`emp_no`,`from_date`));

    答案

    select (max(salary)-min(salary)) growth from salaries
    where emp_no=10001 
     
     
     
  • 相关阅读:
    mysql服务器上的mysql这个实例中表的介绍
    mysql的innodb存储引擎和myisam存储引擎的区别
    Ubuntu配置java环境变量
    Android_adb shell am/pm使用
    tty相关内容
    Ubuntu和windows共享文件夹
    蓝牙查询网站
    Vim折叠模式设置
    ubuntu下安装jdk
    Linux下Gcc生成和使用静态库和动态库详解
  • 原文地址:https://www.cnblogs.com/wbf980728/p/14032418.html
Copyright © 2011-2022 走看看