Mysql如何查出排名 Nth的数据

初始化数据

CREATE TABLE `employee` (
  `ID` int(11) DEFAULT NULL,
  `NAME` varchar(100) COLLATE utf8_bin DEFAULT NULL,
  `DEPARTMENT` int(11) DEFAULT NULL,
  `EMAIL` varchar(100) COLLATE utf8_bin DEFAULT NULL,
  `salary` decimal(10,2) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;


INSERT INTO EMPLOYEE VALUES (1,'Tl1',101,'Tl1@ls.com',2536.46);
INSERT INTO EMPLOYEE VALUES (2,'Tl2',102,'Tl2h@ls.com',3536.46);
INSERT INTO EMPLOYEE VALUES (3,'Tl3',103,'Tl3h@ls.com',5536.46);
INSERT INTO EMPLOYEE VALUES (4,'Tl4',104,'Tl4h@ls.com',5536.46);
INSERT INTO EMPLOYEE VALUES (5,'Tl1',105,'Tl1@ls.com',2536.46);
INSERT INTO EMPLOYEE VALUES (6,'Tl2',106,'Tl2h@ls.com',3656.46);
INSERT INTO EMPLOYEE VALUES (7,'Tl3',107,'Tl3h@ls.com',4626.46);
INSERT INTO EMPLOYEE VALUES (8,'Tl4',108,'Tl4h@ls.com',3214.46);


查询SQl

SELECT *
FROM employee Emp1
WHERE (2) = (
	 SELECT COUNT( DISTINCT ( Emp2.salary ) )
     	FROM employee Emp2
     WHERE Emp2.salary >= Emp1.salary
			)

全部评论

相关推荐

程序员猪皮:看不到八股什么意思
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
11-27 10:52
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务