LintCode MySQL 1918. 第二高的球员的身高

2021-09-07 11:09:53 浏览数 (1)

文章目录

    • 1. 题目
    • 2. 解题

1. 题目

编写一个 SQL 语句,获取球员 (players) 表中第二高的身高 (height)

表定义: players (球员表)

https://www.lintcode.com/problem/1918

2. 解题

  • if(a,b,c), a true,执行 b, 否则 c
代码语言:javascript复制
-- Write your SQL Query here --
-- example: SELECT * FROM XX_TABLE WHERE XXX --
select
(
    if(
        (select count(*) from (select distinct height from players) p) >= 2,
        (select distinct height from players order by height desc limit 1 offset 1),
        NULL
    )
) second_height

0 人点赞