列表

详情


SQL246. 获取employees中的first_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 Parto      
Bamford   
M    
1986-08-28
10004
1954-05-01 Christian  
Koblick   
M    
1986-12-01 
10005
1955-01-21
Kyoichi
Maliniak
M
1989-09-12
10006
1953-04-20
Anneke
Preusig
F
1989-06-02
10007
1957-05-23
Tzvetan
Zielinski
F
1989-02-10
10008
1958-02-19
Saniya
Kalloufi
M
1994-09-15
10009
1952-04-19
Sumant
Peac
F
1985-02-18
10010
1963-06-01
Duangkaew
Piveteau
F
1989-08-24
10011
1953-11-07
Mary
Sluis
F
1990-01-22
请你将employees中的first_name,并按照first_name最后两个字母升序进行输出。
以上示例数据的输出如下:
first_name
Christian  
Tzvetan
Bezalel       
Duangkaew
Georgi
Kyoichi
Anneke
Sumant
Mary
Parto      
Saniya

示例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','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');

输出:

Chirstian
Tzvetan
Bezalel
Duangkaew
Georgi
Kyoichi
Anneke
Sumant
Mary
Parto
Saniya

原站题解

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

Sqlite 解法, 执行用时: 9ms, 内存消耗: 3304KB, 提交时间: 2021-04-28

SELECT first_name FROM employees 
ORDER BY substr(first_name, -2);

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

select first_name
from employees as e
order by substr(e.first_name,-2,2)

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

select first_name from employees
order by substr(first_name,-2,2)

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

select first_name from employees 
order by substr(first_name, length(first_name)-1, 2) asc;

/*select first_name from employees 
order by substr(first_name, -2) asc;

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

select first_name from employees order by substr(first_name,length(first_name)-1, 2)