简体   繁体   English

Sql运行多个查询

[英]Sql running multiple queries

Here is my code to fetch 2nd highest salary in a company... 这是我在公司中获得第二高薪的代码......

select salary from org order by salary desc limit(1,1)

above result will be one row ...with highest salary(100000) ,,,now i want to fetch all employes emp_names with the second highest salary.. how to do that? 上面的结果将是一行...最高薪水(100000),,,现在我想获取所有雇员emp_names与第二高薪..怎么办?

Add DISTINCT to your query (in case multiple people have the same highest salary), and join it like this: 将DISTINCT添加到您的查询中(如果多个人具有相同的最高薪水),并按以下方式加入:

select org.* from org
join (select distinct salary from org order by salary desc limit(1,1)) org_salary
  on org.salary = org_salary.salary

Working sqlfiddle here 在这里工作sqlfiddle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM