zoukankan      html  css  js  c++  java
  • 1、查找最晚入职员工的所有信息

    1、题目描述:

    查找最晚入职员工的所有信息

    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`));

    2、思路:

    (1)order by:先按照hire_data进行排序,因为order by 默认排序是升序ASC,所以要指定排序规则为降序DESC,此时查出来是所有表格数据排序的结果集。这时候还需要对结果集进行过滤,使用limit即可。

    补充:limit用法

     SELECT * FROM table LIMIT 5,10; //检索记录行6-15 

     //为了检索从某一个偏移量到记录集的结束所有的记录行,可以指定第二个参数为 -1:
    SELECT * FROM table LIMIT 95,-1; // 检索记录行 96-last.

       //如果只给定一个参数,它表示返回最大的记录行数目:
    SELECT * FROM table LIMIT 5;     //检索前 5 个记录行
       //换句话说,LIMIT n 等价于 LIMIT 0,n。

    select * from employees order by hire_date desc limit 1;
    select * from employees order by hire_date desc limit 0,1;

    (2)子查询:先找到最大的那个hire_date,然后用where查询

    select * from employees where hire_date=(select max(hire_date) from employees);

     

  • 相关阅读:
    配置 L3 agent
    Why Namespace?
    虚拟 ​router 原理分析
    创建 router 连通 subnet
    用 config drive 配置网络
    cloud
    写在最前面
    使用apktool工具遇到could not decode arsc file的解决办法
    php-fpm优化
    解决官网下载jdk只有5k大小的错误
  • 原文地址:https://www.cnblogs.com/guoyu1/p/12189240.html
Copyright © 2011-2022 走看看