473,506 Members | 14,630 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

T-SQL or stored procedure to find employees with salary in top 5%

17 New Member
Hello Everyone,

I have a table with the following structure:

Employee ID, Salary.

I want to find employees with top 5% salaries.

Appreciate if someone may please help.

Thanks,
Rupinder
Aug 29 '07 #1
4 2782
azimmer
200 Recognized Expert New Member
Hello Everyone,

I have a table with the following structure:

Employee ID, Salary.

I want to find employees with top 5% salaries.

Appreciate if someone may please help.

Thanks,
Rupinder
Expand|Select|Wrap|Line Numbers
  1. select top 5 percent emp_id, salary
  2. from myTable
  3. order by salary desc
  4.  
Aug 29 '07 #2
rupinderbatra
17 New Member
Expand|Select|Wrap|Line Numbers
  1. select top 5 percent emp_id, salary
  2. from myTable
  3. order by salary desc
  4.  
Thanks for the suggestion but the above query will return top 5 percent rows with salary in descending order. What I am trying to achieve is to have the rows with salary in top 5 percent. for ex: if maximum salary is 100, I want to retrieve all rows with salary >=95.

Thanks,
Rupinder
Aug 29 '07 #3
azimmer
200 Recognized Expert New Member
Thanks for the suggestion but the above query will return top 5 percent rows with salary in descending order. What I am trying to achieve is to have the rows with salary in top 5 percent. for ex: if maximum salary is 100, I want to retrieve all rows with salary >=95.

Thanks,
Rupinder
OK, that's different:
Expand|Select|Wrap|Line Numbers
  1. select empid, salary
  2. from mytable
  3. where salary >= (select 0.95*max(salary) from mytable)
  4.  
Aug 29 '07 #4
rupinderbatra
17 New Member
OK, that's different:
Expand|Select|Wrap|Line Numbers
  1. select empid, salary
  2. from mytable
  3. where salary >= (select 0.95*max(salary) from mytable)
  4.  
Thanks, it worked.
In my actual problem, I had a table with employee and their scores for various campaigns and I had to find top 5% of the cumulative scores of an employee. So, I used temporary tables and applied your logic on the temporary table to make it work.
Thanks once again,
Rupinder
Aug 30 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
6224
by: deprins | last post by:
Hello, I have wrote a stored procedure but its real slow. Its activated by a button on web page but its takes to long to process and the web server gives a timeout message after 5 minutes. Is...
1
3656
by: DB_2 | last post by:
Hello, I created the following stored procedure. (Please ignore the logic in it; at this point it is not complete and I am trying to get the basic structure working first.) CREATE PROCEDURE...
2
3947
by: Not Me | last post by:
Hey, Coming back to a piece of work I did a while back, which used a stored procedure to populate a list box. The SP takes a single parameter, and I think this is the reasoning for using 'exec'...
1
2292
by: Chris | last post by:
Hi, I created a VB SQL CRL Stored procedure for calculating a value. Value is returned as below Using sConn4 As New SqlConnection("context connection=true") sConn4.Open() scmd = New...
3
3400
by: vickilynnpgc | last post by:
I have a tsql stored procedure I want to drag from server explorer onto an xsd file. I get the error ' xml schema could not be interpreted'. The stored procedure does a select from a udf, that's...
0
1669
by: charlesg | last post by:
I have a query that select rows from the employees,salary_head and salary_group tables this is the query SELECT TOP 100 PERCENT dbo.salary_head.salary_group_id, dbo.salary_group.salary_group,...
1
2290
by: satish mullapudi | last post by:
Hi, I am using DB2 v8.2 & jdk 1.4. 1. I have a java program which returns an array which contains 1 to 5 numbers. The code: public class ArrayTest { public static final int ARRAY_SIZE = 5;...
1
6112
by: sheenaa | last post by:
Hello Members, I m creating my application forms in ASP.Net 2005 C# using the backend SQL Server 2005. What i have used on forms :: ? On my first form i have used some...
1
4167
by: zrtv | last post by:
hi All, Iam new in oracle stored procedure, i have one stored procedure and it has to be accessed from vb6. my stored procedure as follows -- employee salary will be entered by the user and...
0
7220
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7371
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7479
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5617
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3188
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1534
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
757
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
410
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.