• 微信公众号：美女很有趣。 工作之余，放松一下，关注即送10G+美女照片！

# SQL实战 6.对于employees表中，给出奇数行的first_name

10小时前 2次浏览

## 描述

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

first_name
Georgi
Anneke

## SQL如下

SELECT b.first_name FROM
employees b join

(
SELECT first_name, ROW_NUMBER() OVER(ORDER BY first_name) N FROM employees
) a on b.first_name=a.first_name  WHERE a.n%2<>0

解法2：

SELECT first_name FROM
(
SELECT first_name , (SELECT COUNT(1) FROM employees  e2 WHERE e1.first_name>e2.first_name) rn FROM employees  e1
) e3 WHERE e3.rn%2=0