SQL255. 给出employees表中排名为奇数行的first_name
描述
对于employees表中,输出first_name排名(按first_name升序排序)为奇数的first_namefirst |
Georgi |
Anneke |
示例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(10005,'1955-01-21','Kyoichi','Maliniak','M','1989-09-12'); INSERT INTO employees VALUES(10006,'1953-04-20','Anneke','Preusig','F','1989-06-02');
输出:
Georgi Anneke
Sqlite 解法, 执行用时: 9ms, 内存消耗: 3368KB, 提交时间: 2021-09-09
SELECT e1.first_name FROM employees e1 WHERE (SELECT COUNT(*) FROM employees e2 WHERE e1.first_name >= e2.first_name)%2 =1
Sqlite 解法, 执行用时: 10ms, 内存消耗: 3308KB, 提交时间: 2020-07-21
SELECT e1.first_name FROM employees e1 where (SELECT COUNT(*) FROM employees e2 WHERE e1.first_name >= e2.first_name) % 2 = 1
Sqlite 解法, 执行用时: 10ms, 内存消耗: 3320KB, 提交时间: 2020-08-08
SELECT e1.first_name FROM employees e1 WHERE (SELECT COUNT(*) FROM employees e2 WHERE e1.first_name >= e2.first_name)%2 =1;
Sqlite 解法, 执行用时: 10ms, 内存消耗: 3320KB, 提交时间: 2020-07-13
SELECT e1.first_name FROM employees e1 WHERE (SELECT COUNT(*) FROM employees e2 WHERE e1.first_name >= e2.first_name)%2=1;
Sqlite 解法, 执行用时: 10ms, 内存消耗: 3320KB, 提交时间: 2020-07-12
select e1.first_name from employees e1 where ( select count(*) from employees e2 where e1.first_name>=e2.first_name )%2 = 1