选择最低工资行

时间:2016-01-02 03:59:37

标签: java mysql

我有表格列

"id,name,city,salary" 

我想得到“最低薪水的人”和“最高薪水的人”。 我试过这个

SELECT max(salary) FROM `employee`;

但它只提供薪水栏。我想得到这个结果(如果最低工资= 1500),

001 | Lahiru | matara | 1500

1 个答案:

答案 0 :(得分:3)

同时获得minmax工资人员详情。

Sub-Query方法:

SELECT * 
FROM   employee 
WHERE  salary IN(SELECT Max(salary)  
                 FROM   employee 
                 UNION ALL 
                 SELECT Min(salary) 
                 FROM   employee) 

INNER JOIN方法

SELECT * 
FROM   employee E 
       INNER JOIN (SELECT Max(salary) AS max_min_sal 
                   FROM   employee 
                   UNION 
                   SELECT Min(salary) 
                   FROM   employee) A 
               ON A.max_min_sal = E.salary