输入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'); 请你在不打乱原序列顺序的情况下,输出:按first_name排升序后,取奇数行的first_name。
时间: 2023-08-06 15:11:47 浏览: 69
C++编程中__if_exists与__if_not_exists语句的用法
可以使用以下 SQL 语句实现:
```
SELECT first_name
FROM (
SELECT first_name, ROW_NUMBER() OVER (ORDER BY first_name ASC) AS row_num
FROM employees
) AS temp
WHERE row_num % 2 = 1
```
这个 SQL 查询语句会首先按照 `first_name` 升序排列,然后使用 `ROW_NUMBER()` 函数为每一行添加一个行号。接着,我们将这个结果作为一个临时表 `temp`,并从中选出行号为奇数的 `first_name` 值。最终得到的结果即为按 `first_name` 排升序后,取奇数行的 `first_name`。
阅读全文