【leetcode】database Second Highest Salary
2015-08-05 21:13
441 查看
Write a SQL query to get the second highest salary from the
For example, given the above Employee table, the second highest salary is
问题很简单,就是要select 出第二大的Salary。
我的思路就是:
先找出最大的Salary,然后在找出不等于最大Salary的最大Salary,也就是第二大的Salary。
一次AC,表示高兴。
一次AC,还是比较意外的。
Employeetable.
+----+--------+ | Id | Salary | +----+--------+ | 1 | 100 | | 2 | 200 | | 3 | 300 | +----+--------+
For example, given the above Employee table, the second highest salary is
200. If there is no second highest salary, then the query should return
null.
问题很简单,就是要select 出第二大的Salary。
我的思路就是:
先找出最大的Salary,然后在找出不等于最大Salary的最大Salary,也就是第二大的Salary。
一次AC,表示高兴。
SELECT MAX(Salary) FROM Employee WHERE Salary != (SELECT MAX(Salary) FROM Employee);
一次AC,还是比较意外的。
相关文章推荐
- 杭电ACM 2097:Sky数
- POJ-5339 Untitled
- 关于strong、copy、weak、assign的常规用法
- Memcached、Redis、RDD(Spark)的数据处理性能对比(Efficient in-memory data management: an analysis论文翻译)
- GDAL库调试(包括跨语言调试)
- 央视连续抨击百度推广黑幕
- 运行 & Cmd
- iOS开发-18.两种方法实现抽屉效果
- 虚拟化项目之运维实践 6
- bootstrap(手风琴、图片轮换和固定定位)
- USACO 2.2.2 Subset Sums
- poj 3592 强连通分量+最长路(spfa或者dp)(Instantaneous Transference)
- 大白菜使用
- Windows/MFC_三个退出程序消息:WM_CLOSE、WM_DESTROY、WM_QUIT
- UE4蓝图用户指南
- BNUOJ 13047 Greatest Parent(要说LCA有点勉强(。・∀・)ノ゙)
- iOS设计模式之原型模式
- C程序设计语言(K&R) 笔记2
- 用代码关闭程序的正确做法!---向窗口发送WM_CLOSE消息
- hdoj 2196 Computer 【树的直径 求每个点的最长路】