2022-11-19:第二高的薪水。表结构和数据的sql语句如下,输出200,因为200是第二大的。请问sql语句如何写?
DROP TABLE IF EXISTS `employee`;
CREATE TABLE `employee` (
`id` int(11) NOT NULL,
`salary` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO `employee` VALUES ('1', '100');
INSERT INTO `employee` VALUES ('2', '200');
INSERT INTO `employee` VALUES ('3', '300');
答案2022-11-19:
sql语句如下:
SELECT
IFNULL(
(SELECT DISTINCT salary
FROM employee
ORDER BY salary DESC
LIMIT 1 OFFSET 1),
NULL) AS SecondHighestSalary
结果如下: