如何写查询 [英] How to write a query

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

问题描述

大家好,


我有这样的桌子..

EMP_NO EMP_NAME SALARY
1巴沙1000
2个Pavan 2500
3 santu 2000
4 karthik 500
5 naresh 1500

如何编写查询以获取最高薪水或基于薪资在另一行中排名的查询,例如这样

EMP_NO EMP_NAME SALARY最高
1 Basha 1000 4
2 Pavan 2500 1
3 santu 2000 2
4 karthik 500 5
5 naresh 1500 3


问候,
S.Inayat Basha.

Hi all,


I have a table like this..

EMP_NO EMP_NAME SALARY
1 Basha 1000
2 Pavan 2500
3 santu 2000
4 karthik 500
5 naresh 1500

how to write a query to get the highest salary or ranking based on salary in another row like this

EMP_NO EMP_NAME SALARY Highest
1 Basha 1000 4
2 Pavan 2500 1
3 santu 2000 2
4 karthik 500 5
5 naresh 1500 3


Regards,
S.Inayat Basha.

推荐答案

嗨 伊纳亚特,

请使用以下内容:

Hi Inayat,

Please use following:

--Table creation
CREATE TABLE Employee
(Name VARCHAR(10), 
Age INT, 
Salary INT)

--Inserting entries
insert into Employee
select 'Haidarali',29,29000 union all
select 'Rashidali',2,20000 union all
select 'Imdadhusen',28,50000 union all
select 'Abbas',25,58000

--ordering entry by rank
SELECT RANK() OVER(ORDER BY Salary DESC) AS Rank,* FROM dbo.Employee;




如有任何疑问,请让我知道.

请提供"投票":thumbsup:如果有帮助,请提供"接受答案",如果这是正确的答案.:rose:

谢谢,
Imdadhusen




Please do let me know, if you have any doubt.

Please provide "Vote":thumbsup: if this would be helpful, and make "Accept Answer" if this would be correct answer.:rose:

Thanks,
Imdadhusen


RANK将帮助您完成同样的任务.

A RANK will help you to do the same.

SELECT EMP_NO, EMP_NAME, SALARY,
       RANK() OVER (ORDER BY SALARY DESC) AS Highest
FROM TABLENAME
ORDER BY EMP_NO


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

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