1. 显示系统时间(注:日期+时间)

      1. SELECT NOW()
      2. FROM DUAL;
    2. 查询员工号,姓名,工资,以及工资提高百分之 20% 后的结果(new salary)

      1. SELECT employee_id, last_name, salary, salary * 1.2 "new salary"
      2. FROM employees;
    3. 将员工的姓名按首字母排序,并写出姓名的长度(length)

      1. SELECT last_name, LENGTH(last_name)
      2. FROM employees
      3. ORDER BY last_name DESC;
    4. 查询员工 id,last_name,salary,并作为一个列输出,别名为 OUT_PUT

      1. SELECT CONCAT(employee_id, ',' , last_name , ',', salary) OUT_PUT
      2. FROM employees;
    5. 查询公司各员工工作的年数、工作的天数,并按工作年数的降序排序。

      1. SELECT DATEDIFF(SYSDATE(), hire_date) / 365 worked_years,
      2. DATEDIFF(SYSDATE(), hire_date) worked_days
      3. FROM employees
      4. ORDER BY worked_years DESC
      1. SELECT (TO_DAYS(SYSDATE())-TO_DAYS(hire_date)) / 365 worked_years,
      2. (TO_DAYS(SYSDATE())-TO_DAYS(hire_date)) worked_days
      3. FROM employees
      4. ORDER BY worked_years DESC
    6. 查询员工姓名,hire_date , department_id,满足以下条件:雇用时间在 1997 年之后,department_id 为 80 或 90 或110, commission_pct 不为空

      1. SELECT last_name, hire_date, department_id
      2. FROM employees
      3. # WHERE hire_date >= '1997-01-01'
      4. # WHERE hire_date >= STR_TO_DATE('1997-01-01', '%Y-%m-%d')
      5. WHERE DATE_FORMAT(hire_date,'%Y') >= '1997'
      6. AND department_id IN (80, 90, 110)
      7. AND commission_pct IS NOT NULL
    7. 查询公司中入职超过 10000 天的员工姓名、入职时间

      1. SELECT last_name,hire_date
      2. FROM employees
      3. # WHERE TO_DAYS(NOW()) - to_days(hire_date) > 10000;
      4. WHERE DATEDIFF(NOW(),hire_date) > 10000;
    8. 使用 case-when,按照下面的条件

      1. job grade
      2. AD_PRES A
      3. ST_MAN B
      4. IT_PROG C
      5. SA_REP D
      6. ST_CLERK E
      1. SELECT last_name Last_name,
      2. job_id Job_id, CASE job_id WHEN 'AD_PRES' THEN 'A'
      3. WHEN 'ST_MAN' THEN 'B'
      4. WHEN 'IT_PROG' THEN 'C'
      5. WHEN 'SA_REP' THEN 'D'
      6. WHEN 'ST_CLERK' THEN 'E'
      7. END "grade"
      8. FROM employees;