列表

详情


SQL209. 查找employees表emp_no与last_name的员工信息

描述

有一个员工表employees简况如下:
emp_no
birth_date
first_name
last_name
gender hire_date
10001
1953-09-02
Georgi
Facello
M 1986-06-26
10002
1964-06-02
Bezalel
Simmel
F 1985-11-21
10003
1959-12-03
Bezalel
Mary M 1986-08-28
10004
1954-05-01
Christian
Koblick
M 1986-12-01
10005 1953-11-07 Mary Sluis F 1990-01-22

请你查找employees表所有emp_no为奇数,且last_name不为Mary的员工信息,并按照hire_date逆序排列,以上例子查询结果如下:
emp_no birth_date first_name last_name gender hire_date
10005
1953-11-07 Mary
Sluis   F
1990-01-22
10001 1953-09-02 Georgi Facello   M 1986-06-26

示例1

输入:

drop table if exists  `employees` ; 
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 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','Bezalel','Mary','M','1986-08-28');
INSERT INTO employees VALUES(10004,'1954-05-01','Chirstian','Koblick','M','1986-12-01');
INSERT INTO employees VALUES(10005,'1953-11-07','Mary','Sluis','F','1990-01-22');

输出:

10005|1953-11-07|Mary|Sluis|F|1990-01-22
10001|1953-09-02|Georgi|Facello|M|1986-06-26

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

Sqlite 解法, 执行用时: 9ms, 内存消耗: 3372KB, 提交时间: 2021-08-09

select * 
from employees
where emp_no % 2 = 1 and last_name <> 'Mary'
order by hire_date desc

Sqlite 解法, 执行用时: 9ms, 内存消耗: 3380KB, 提交时间: 2021-08-09


select * from employees where emp_no % 2 == 1 and last_name != 'Mary'
order by hire_date desc

Sqlite 解法, 执行用时: 9ms, 内存消耗: 3408KB, 提交时间: 2021-08-09

select *from employees
where emp_no % 2=1
and last_name !='Mary'
order by hire_date desc

Sqlite 解法, 执行用时: 10ms, 内存消耗: 3168KB, 提交时间: 2020-12-24

select *
from employees
where emp_no%2=1 and last_name !='Mary'
order by hire_date desc

Sqlite 解法, 执行用时: 10ms, 内存消耗: 3172KB, 提交时间: 2020-10-29

select *
from employees 
where emp_no%2=1
order by hire_date desc