sql - 如何从下表中检索最高和最低工资?

标签 sql oracle select oracle11g

我有员工表

 EMP_ID | F_NAME    | L_NAME  | SALARY | JOINING_DATE                 | DEPARTMENT
-----------------------------------------------------------------------------------
 101    | John      | Abraham | 100000 | 01-JAN-14 09.15.00.000000 AM | Banking
 102    | Michel    | Clarke  | 800000 |                              | Insaurance
 102    | Roy       | Thomas  | 70000  | 01-FEB-13 12.30.00.000000 PM | Banking
 103    | Tom       | Jose    | 600000 | 03-FEB-14 01.30.00.000000 AM | Insaurance
 105    | Jerry     | Pinto   | 650000 | 01-FEB-13 12.00.00.000000 PM | Services
 106    | Philip    | Mathew  | 750000 | 01-JAN-13 02.00.00.000000 AM | Services
 107    | TestName1 | 123     | 650000 | 01-JAN-13 12.05.00.000000 PM | Services
 108    | TestName2 | Lname%  | 600000 | 01-JAN-13 12.00.00.000000 PM | Insaurance

我想从上面的oracle sql表中找到最高和最低工资。 如果我这样做

 select max(salary) from (select * from (select salary from employee) where   rownum <2);

它返回MAX(SALARY) = 100000,而它应该返回800000

如果我这样做

select max(salary)
  from (select * from (select salary from employee) 
         where rownum <3);

它返回MAX(SALARY) = 800000

如果我这样做

select min(salary)
  from (select * from(select salary from employee)
         where rownum < 2);

它将返回 MIN(SALARY) = 100000,而它应该返回 70000

此查询有什么问题?

正确的查询应该是什么?

最佳答案

您不需要所有这些子查询:

SELECT MAX(salary), MIN(salary)
FROM   employee

关于sql - 如何从下表中检索最高和最低工资?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31717465/

相关文章:

mysql - 按计数降序选择不同的行

oracle - Sql*plus 总是返回退出代码 0?

oracle - 将行类型变量复制到另一个变量

select - 戈朗 : select statement exits when it shouldn't

sql - 为什么这些是字符串末尾的问号

java - 使用触发器确保数据一致性

javascript - 将列表显示为 <选项值 ="">

sql - 使用 Node.js 和 sqlite3 添加具有多列的行

sql - SQL 嵌套注释背后的算法

mysql - 使用单个查询从 mysql 表中删除 csv 文件值