牛客网上的一道sql编程题

321 阅读1分钟

题目描述

对于employees表中,给出奇数行的first_name

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

解法有点“玄学":

select A.first_name from employees as A 
where (select count(*) from employees as B where A.first_name <= B.first_name) % 2 = 1;

其中的 <= 是为什么?