我有表格列
"id,name,city,salary"
我想得到“最低薪水的人”和“最高薪水的人”。 我试过这个
SELECT max(salary) FROM `employee`;
但它只提供薪水栏。我想得到这个结果(如果最低工资= 1500),
001 | Lahiru | matara | 1500
答案 0 :(得分:3)
同时获得min
和max
工资人员详情。
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