题解 | #对于employees表中,给出奇数行的first_name#
对于employees表中,给出奇数行的first_name
http://www.nowcoder.com/practice/e3cf1171f6cc426bac85fd4ffa786594
- 1.根据first_name 经行排序给出rank
- 2.去掉rank是偶数的
- 3.输出不需要排序
解题: 利用rank()over()经行排序或者dense_rank()over()查出first_name 和rank作为新表a; 去除rank是偶数的,利用子查询去掉排序;
select first_name from employees where first_name in
(select first_name from
(select first_name,dense_rank()over(order by first_name) r from employees order by first_name desc) a
where r%2!=0);