查询的流程? [英] Process flow of query?

查看:79
本文介绍了查询的流程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个脚本来获得薪水最高的前三名员工: -

但是我无法完成流程步骤: - 请简要帮助我执行订单和流程简介可能。



请查看下面的查询: -

  SELECT  EmpName,Salary  FROM  EmpSalary E1  WHERE  3> 
SELECT COUNT( DISTINCT 薪资) FROM EmpSalary E2 WHERE E2.Salary> E1.Salary)





谢谢



问候,
$ b $b♣≈Ω°±Σⁿ

解决方案

< blockquote>



我们假设我们有以下数据:

  ID   EmpName  薪水 
1 Tom 20000.0000
2 John 33000.0000
3 Andrew 30000.0000
4 Jane 33000.0000
5 Jill 37000.0000



如你所见,约翰和简赚的钱相同(33000或第二高薪)。



如果你只想得到3名薪水最高的员工:

  SELECT   TOP   3  EmpName,
薪资
FROM EmpSalary
ORDER BY 薪水 DESC



结果:

  EmpName  薪水 
Jill 37000.0000
约翰33000.0000
简33000.0000





但是,如果你想通过不同的工资来获得薪水最高的员工,那么工资问题就会出现问题,或者工资重复怎么办?如果你想在同一个工资的情况下只得到一个人,你可以做这样的事情( SQL Server 2005 或更高版本):

  SELECT   TOP   3  EmpName, 
薪资
FROM SELECT EmpName,
薪水,
ROW_NUMBER()
OVER
PARTITION BY 薪资
ORDER BY EmpName) AS RowNumber
FROM EmpSalary) AS E
WHERE E.RowNumber = 1
ORDER BY 薪资 DESC



结果:

  EmpName  薪水 
Jill 37000.0000
简33000.0000
Andrew 30000.0000



在这种情况下,通过按姓名获取第一名员工(ORDER BY)解决了重复工资问题EmpName)。



我希望这很有用。


I have a script to get top 3 employees whose salaries are highest:-
But i am unable to get the process flow step:- Kindly help me for execution order and process flow in brief as possible.

Kindly have a look on below query:-

SELECT EmpName, Salary FROM EmpSalary E1 WHERE 3>
(SELECT COUNT(DISTINCT Salary) FROM EmpSalary E2 WHERE E2.Salary>E1.Salary)



Thanks

Regards,
♣ ≈Ω°±Σⁿ

解决方案

Hi,

Let's assume that we have the following data:

ID	EmpName	Salary
1	Tom	20000.0000
2	John	33000.0000
3	Andrew	30000.0000
4	Jane	33000.0000
5	Jill	37000.0000


As you can see, John and Jane earns the same amount of money (33000 or 2nd highest salary).

If you just want to get 3 employees with the highest salaries:

SELECT TOP 3 EmpName,
             Salary
FROM   EmpSalary
ORDER  BY Salary DESC


Result:

EmpName	Salary
Jill	37000.0000
John	33000.0000
Jane	33000.0000



But if you want to get employees with the highest salaries by distinct salary, there is a duplicate salaries problem or "What to do in the case of duplicate salaries?" If you want to get only one person in the case of the same salary, you could do something like this (SQL Server 2005 or greater):

SELECT TOP 3 EmpName,
             Salary
FROM   (SELECT EmpName,
               Salary,
               ROW_NUMBER()
                 OVER (
                   PARTITION BY Salary
                   ORDER BY EmpName) AS RowNumber
        FROM   EmpSalary) AS E
WHERE  E.RowNumber = 1
ORDER  BY Salary DESC


Result:

EmpName	Salary
Jill	37000.0000
Jane	33000.0000
Andrew	30000.0000


In this case, duplicate salaries problem was solved by taking the first employee by name (ORDER BY EmpName).

I hope this was helpful.


这篇关于查询的流程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆