題目描述:
查詢最晚入職員工的所有資訊:
create tableemployees
(
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
));
輸入描述:
無輸出描述:
emp_no
birth_date
first_name
last_name
gender
hire_date
10008
1958-02-19
saniya
kalloufi
m1994-09-15
題目解析:
解法一:子查詢
先找出 hire_date 欄位的最大值,再把該值當成 employees 表的 hire_date 查詢條件。
select
*from employees
where hire_date =
(select
max(hire_date)
from employees)
;
解法二:排序,降序。
對hire_date欄位排序降序,此時最晚的時間排在第乙個,再用limit取出。
select
*from employees
order
by hire_date desc
limit0,
1;
注:
limit m,n : 表示從第m+1條開始,取n條資料;
limit n : 表示從第0條開始,取n條資料,是limit(0,n)的縮寫。
本題limit 0,1 表示從第(0+1)條資料開始,取一條資料,即取出最晚入職員工。
SQL練習 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,gend...
sql演算法 查詢最晚入職員工的所有資訊
建表語句如下 create table employees emp no int 11 notnull birth date date notnull first name varchar 14 not null last name varchar 16 not null gender char 1...
牛客 資料庫SQL實戰 查詢最晚入職員工的所有資訊
題目描 述 color題目描述 題目描述 查詢最晚入職員工的所有資訊 create table employees emp no int 11 notnull birth date date notnull first name varchar 14 not null last name varch...