SQL 61) 输出first_name排名为奇数的first_name
对于employees表中,给出奇数行的first_name
http://www.nowcoder.com/questionTerminal/e3cf1171f6cc426bac85fd4ffa786594
一开始是用窗口函数做的,但是怎么都做不对...
SELECT a.first_name FROM ( SELECT first_name, row_number()over(ORDER BY first_name)AS rank_num FROM employees )a WHERE a.rank_num%2 = 1;因为实在是无法理解COUNT的做法,看了大家的评论说是
- 题目中要求“输出的结果不需排序”……
SELECT e.first_name FROM employees e JOIN ( SELECT first_name , ROW_NUMBER() OVER(ORDER BY first_name ASC) AS r_num FROM employees ) AS t ON e.first_name = t.first_name WHERE t.r_num % 2 = 1;加上表连结就能通过了(这样结果就不排序了)
SQL 文章被收录于专栏
SQL