什么是storeprocedure中给定表的SQL查询? [英] what is SQL query for given table in storeprocedure ?

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

问题描述

我有一张桌子:员工

字段是:

emp_id

emp_name

emp_salary





我想要10个员工名单,薪水最高。

请帮助我。

解决方案

尝试这个....



 选择 a.client_id 作为 client_id,b.city_name 作为 city_name,a.client_name  as  client_name 来自客户端a  inner   join  
city b on a.city_id = b.city_id 其中 a.city_id=@city_id


使用此...

 < span class =code-keyword>选择 * 来自 

选择 emp_id,emp_name,emp_salary, Rank() over order by emp_Salary desc as Sal_Rank
来自员工

as temp 其中 Sal_Rank< = 10
订单 Sal_Rank,Emp_Id



 这将为员工提供前10名最高薪水。 
例如..
empid name sal sal_rank
------------------------------- ---
1 samarth 100000 1
2 aadarsh 100000 1
5 tarak 90000 2
...

< br $>
快乐编码!

:)


http://blog.sqlauthority.com/2008/04/02/ sql-server-find-nth-highest-salary-of-employee-query-to-retrieve-the-nth-maximum-value / [ ^ ]

I have one table: employee
fields are:
emp_id
emp_name
emp_salary


I want 10 employee list whose salary is highest.
please help me.

解决方案

try this....

select a.client_id as client_id,b.city_name as city_name,a.client_name as client_name from client a inner join
city b on a.city_id=b.city_id where a.city_id=@city_id


use this...

select * from
(
    select emp_id,emp_name,emp_salary, Rank() over (order by emp_Salary desc) as Sal_Rank
    from employee
)
as temp where Sal_Rank<=10 
Order by Sal_Rank, Emp_Id


this will give employees list having top 10 highest salaries.
e.g...
empid  name      sal     sal_rank
----------------------------------
1      samarth   100000  1
2      aadarsh   100000  1
5      tarak     90000   2
...


Happy Coding!
:)


http://blog.sqlauthority.com/2008/04/02/sql-server-find-nth-highest-salary-of-employee-query-to-retrieve-the-nth-maximum-value/[^]


这篇关于什么是storeprocedure中给定表的SQL查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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