# How To Get Top Three Salary Getters From Table Employee

Mar 1, 2007

Dear All,
i want to know how to get top three salary getters from the employee(eid , ename, salary) table

i tried this
select  top 3  salary from employee order by salary desc

but it gives me top three salary record say there is salary 1000,1200,1300,1300,1500
then my query return me 1500,1300,1200 whereas i want to 1500,1300,1300,1200

how can i do it

thanks

## SQL Server 2012 :: Find All Employee Whose Salary Sum Is 80% Of Sum Of Salary Of All Employees

Aug 14, 2014

Let us assume that there are 100 employee in a company. And sum of salary of all employee is 10000. Find list of highest paid employees whose sum of salary is 8000. Remaining employee will fall in 20% bracket.

## Update The Salary Of Each Manager To Be Double The Average Salary Of The Employees He/she Manages

Mar 23, 2006

create table employee(empid int,empname varchar(20),managerid int notnull, sal int)insert into employee values(1,'ranga',22,5000)insert into employee values(2,'satish',22,8000)insert into employee values(3,'sunil',11,4500)insert into employee values(4,'sridhar',22,2000)insert into employee values(5,'ramesh',33,12000)insert into employee values(6,'srini',22,16000)insert into employee values(7,'sashi',33,54000)insert into employee values(8,'rajani',22,71000)insert into employee values(9,'praveen',11,6060)insert into employee values(10,'bhaskar',22,11120)insert into employee values(11,'baba',33,9000)create table employment (managerid int,managername varchar(20),sal int)insert into employment values(11,'rob',2500)insert into employment values(22,'babu',5000)insert into employment values(33,'ram',6000)now my problem isUpdate the salary of each manager to be double the averagesalary of the employees he/she managespls helpsati

## Transact SQL :: Joining A Calendar Table And Employee Table?

Apr 20, 2015

I run into a problem when asking to show a query of employee vacation days.

table 1:
column1  is dates
e.g.
2015-01-01
2015-01-02
2015-01-03
.
.
.
2015-12-31

table2:
employeeID
vacation_date
Tom
2015-01-03
Tom
2015-01-04
David
2015-01-04
John
2015-01-08
Mary
2015-01-012

My query output need to be:

2015-01-01
2015-01-02
2015-1-03
Tom
2015-01-04
Tom
2015-01-04
David
2015-01-05
2015-01-06
2015-01-07
2015-01-08
John
2015-01-09
2015-01-10
2015-01-11
2015-11-12
Mary

... etc... all the way to 2015-12-31

when i use left outer join, i only record one employee per date.

## Using Employee/Boss Self Referencing Table

Feb 28, 2008

I have an Employee table that has
EmployeeID (PK)
SupervisorID (which is really just another EmployeeID)
..random junk...

Now that part makes sense, everyone gets one and only one boss.

Their boss can change, and therefore the SupervisorID would be updated.

Now I have an EmployeeEvals table that has quarterly evaluation data.

I want to relate these two tables.

Eval table has
EvalID (PK)
ReviewedEmployeeID (the one being evaluated)
SupervisorID (the one doing the evaluation)

Now I need to link this back to the employee table (at least I think I do).

So I would want to relate it by the ReviewedEmployeeID going back to EmployeeID in the employee table and I also want the SupervisorID to do the same...

But of course that won't work because that would seem to indicate that a single record on the Employees table (say EmployeeID 55) should have a matching (or could) record in the Eval table that would look like
EvalID: 12345
ReviewedEmployeeID: 55
SupervisorID: 55

which of course wouldn't happen as an employee wouldn't evaluate themself.

How do I handle the relationships for this properly?

Do I just not link the SupervisorID back to anything?

## Employee Data - Show Changes From And To In History Table

Jun 27, 2014

I have a table history of Employee data.

id | EmpNo | EmpName | MobileNo | Email | EmpSSS | UpdateDate | UpdateUser

I have to make a stored procedure that will show the history and changes made to a given EmpNo, with the UpdateDate, UpdateUser and indicate which field is modified. Ex. Employee Mobile number was changed from '134151235' to '23523657'.

Result must be:

EmpNo | UpdateDate | UpdateUser | Field changed | Change from | change to

## Transact SQL :: Select Last Inserted Value Row ID In Employee Table?

Nov 2, 2015

<g class="gr_ gr_54 gr-alert gr_gramm Grammar multiReplace" data-gr-id="54" id="54">I want</g> to get row number of last inserted into employee table?

How can i get it @@identity function returns null.

is there any way to do it?

## Query To Find Manager Name From Employee Table Without Joins

Oct 25, 2012

Table structure is very simple as below and I know there are solutions with joins (Left outer joins), need to know if it is possible to get o/p without using joins

Note:- also need records who doesn't have manager (null)

table structure
eid------ename------mgrid
1------Nancy------2
2------Andrew------null
3------Janet ------2
4------Margaret------2
5------Steven------4
6------Michael ------5

o/p
Employee------Manager
Nancy------Andrew
Andrew------Null
Janet ------Andrew
.
.

## I'm Trying To Get The Last Activity Date From W/in A Table Where There Are Multiple Rows Per Employee

Apr 22, 2008

Hi, I have been struggling trying to design a query that will alow be to select the most recent date in a table
and I'm obviously not having much luck

This is basically the table layout, note each employee can have multiple rows with different dates

Employee_ID

Last_Name

First_Name

Evaluation_Date

Evaluation_Score

1

Jones

Tom

01/04/07

40

1

Jones

Tom

01/.12/07

50

1

Jones

Tom

04/01/08

60

2

Smith

Ed

02/14/05

70

2

Smith

Ed

03/18/06

80

3

Brown

John

06/23/04

80

3

Brown

John

12/23/04

79

3

Brown

John

01/07/06

50

3

Brown

John

10/22/08

69

What I'd like to do would be to write some thing that would return the following, just the last date of the evaluation & whatever relevant data is in the table

Employee_ID

Last_Name

First_Name

Evaluation_Date

Evaluation_Score

1

Jones

Tom

04/01/08

60

2

Smith

Ed

03/18/06

80

3

Brown

John

10/22/08

69

I've looked at select distinct and the date operatives with out any success.

Thanks Much
Vince

## Max Average Salary

May 8, 2012

Select * from personnel

where salary > ALL (SELECT AVG (salary) from personnel group by bolno)

And how i find max average salary?

## Need -&> Max(sum(salary)) Query

Mar 20, 2004

hi

i have a table employee:

dept ename salary
---- --------- -------
10 A 2500
20 B 3500
30 C 4000
20 D 5500
10 E 4500
30 F 5200

FIRST QUERY:
select dept,sum(salary) from employee group by dept

the above one is working fine..

after working the first query output,
i want to select the dept,max(sum(salary)) from the table...

how?? could any one send me immediately...

## Hiked Salary...

Oct 20, 2005

--Table Empmaster:-
create table Empmaster
(
empid int identity(1,1) constraint pkempid primary key clustered,
empname varchar(10),
empsalary numeric
)

insert Empmaster(empname,empsalary)values('Imran',5000)
insert Empmaster(empname,empsalary)values('Raja',5000)

--Table Salary:-
create table Salary
(
salid int identity(1,1) constraint pksalid primary key clustered,
empid int constraint fkempid foreign key references Empmaster(empid),
dos varchar(10),
salary numeric
)

insert Salary(empid,dos,salary)values('1','2005-08-01','5000')
insert Salary(empid,dos,salary)values('2','2005-08-01','5000')
insert Salary(empid,dos,salary)values('1','2005-09-01','5000')
insert Salary(empid,dos,salary)values('2','2005-09-01','7000')
insert Salary(empid,dos,salary)values('1','2005-10-01','7000')
insert Salary(empid,dos,salary)values('2','2005-10-01','7000')

i have two tables with relations. how do i find out whose salary has been hiked for the 9th month?

## Max Salary Query

Mar 19, 2007

Hi

How to get the maximum salry from a table without using top and
aggreate function

thanks

asm

## SQL To Increment Salary

Sep 26, 2007

i want to write a SQL statement to increment the salary by 10% for technicians who have done three tests on a particular date.

there are two employee types.(1)technicians (2)traffic controllers.
employee category is defined in "Type" attribute of Employee table. the increment should happen only to technicians.thank you in advance.

Employee (EmployeeID,Name,Salary,Tpye)

TestEmployee(TestNo,EmployeeID,Hrs)

Test(TestNo,TestDate,Result)

## How To Write A Query For 1st, 2nd, 3rd Max Salary

Apr 18, 2006

employee table having columns employeeid, salary

i want to write a query to get 1st, 2nd and 3rd max salary ?

## SQL Server DBA Salary Survey

Aug 29, 2006

I am going into salary negotiationyearly review next month after my week off and I am trying to determine what to ask for. I am thinking another 10K and an extra week off would not be unreasonable, but I wanted to get some idea of what you guys think I should ask for in terms of pay.I have been developing software for seven years and I have been a dba for a little over five. I live in pricey northern Virginia. On a fairly regular basis I do about 55 to 60 hour weeks. On my DBA team, I am the only one who can handle both development and production tasks. The others are strictly developers. Although I have been relieved of most of my customer support tasks by our newbie, the customer support manager still brings the nastier bits to me. It is my perception that the more complex tasks get assigned to me. I get told on a regular basis that I am the best dba this place has ever had and other embarrassing accolades are regularly thrown my way. After a year, other than my boss I am the dba that has been here the longest in high turnover high burnout company. This year as we try to move to a SAP model, it looks like we will be going to 24/7 support on a disaster recovery model I am designing and implementing, so I guess I am getting the pager.So how much money should I be asking for?you can PM me with a number if you want.

## How To Sum All Salary In A Year Given To Employees

Dec 8, 2011

I need to calculate the salary given to all employees in a year

Code:
select sum(emp_total_sal)from emp_salary

How to modify this code to get what i need ?

## How To Know When Total Salary Is At Certain Amount

Jul 24, 2013

I would like to know how to use a criterion on this example. I want to know only when the total salary is at a certain amount

SELECT SUM (salary) as Total Salary
FROM employees
WHERE Total Salary > 25000; ---this is where i am having issue

## Employees And Their Department Who Is Top Salary

Dec 4, 2006

i have 2 tables emp and dept

emp has columns:
empid(pk),empname,deptid(fk),salary

dept has columns:
deptid(pk),deptname

now my aim is:
List of the employees and their department who is top salary earner of the department.

wht i can think of is:

select distinct empname,deptname,max(salary) as 'max salary'
from emp e,dept d
where e.deptid=d.deptid
group by empname,deptname

but it gives unexpected result...

help appreciated

cheers

## Trigger To Increment The Salary By 10%

Sep 25, 2007

i want to write a database trigger to increment the salary by 10% for technicians who have done three tests on a particular date.

there are two employee types.(1)technicians (2)traffic controllers.
employee category is defined in "Type" attribute of Employee table. the increment should happen only to technicians.thank you in advance.

Employee (EmployeeID,Name,Salary,Tpye)
TestEvent(TestNo,EmployeeID,TestDate)

Hussain

## Calculating Salary Per Hour?

Jan 26, 2008

is there a way to create a SELECT clause which counts the accumulate hours from tw columns in same row (entering hour and leaving hour) and then calculating the total price according to a parameter?

Shimi

Sep 26, 2007

aa

## SQL 2012 :: Average Salary For Each Department

Jan 17, 2015

I would like to find the average salary for each department which has min salary

In my case I will have 3 departments which have min salary.

select distinct d.department_name, E.SALARY, avg(E.salary)
FROM EMPLOYEES E JOIN DEPARTMENTS D
ON (E.DEPARTMENT_ID = D.DEPARTMENT_ID)
WHERE E.SALARY = (SELECT MIN(E.SALARY)
FROM EMPLOYEES E JOIN DEPARTMENTS D
ON (E.DEPARTMENT_ID = D.DEPARTMENT_ID))
GROUP BY D.DEPARTMENT_NAME, E.SALARY;

## What Is The Query To Find A 5th Highest Salary With Sqlserver.

Aug 9, 2005

What is the query to find a 5th highest salary.in emp table.i also use top1,top2,..but i don't get a result.what is new in sql server 2005.

## Stored Procedure To Calculate Month Salary(urgent)

Aug 30, 2005

i want to calculate the month salary of an employee.which will be calculated on the basis of previous available leaves and present available leave(i.e) 2 per month.

## TOP 1 For Each Employee

Jul 19, 2013

I need to select last order for each employees for homework. I use northwind database for testing. I can solve it by correlated subquery but the professor said me it is not optimized.

select orderid, customerid, employeeid, orderdate
from orders as o1
where orderdate = (select max(orderdate) from orders as o2 where o1.employeeid = o2.employeeid);

## Update Employee ID Throughout Database

Aug 15, 2012

I have a database that has dozens of tables. Many of these tables reference the employee ID.For example tblDaysOff has a column employeeID that is matched on tblEmployees.ID, and there are many such tables.

Now the employee IDs are changing the way they are generated. Instead of a alphanumeric value being stored as a text value, all employee IDs will be uniqueidentifiers stored as text values.The question is, how can I change every instance of "somevalue" in every record in every column where the column name is "employeeID" in every table in the database to "differentvalue" where employeeID = "somevalue"?This is what I have cobbled together from multiple sources ... but there is a syntax error where @max is located.

Code:
USE CsDB
DECLARE @t TABLE(tRow int identity(1, 1), tSchemaName nvarchar(max), tTableName nvarchar(max))
INSERT INTO @t
SELECT SCHEMA_NAME(schema_id), t.name
FROM sys.tables AS t
JOIN sys.columns c ON c.object_id = t.object_id
WHERE c.name LIKE '%employeeID%'

[code]...

Obviously I don't want to run this and then have to try and recover the database when things go away.

## Sum Quantity With Like Employee And Itemname

Nov 8, 2014

I have a table Item_used like this

Itemname Employee Quantity
pencil samlopez 10
pencil samlopez 5

All I want is to make a report that sum all the quantity of the same items with the same employee like this

Itemname Employee Quantity
pencil samlopez 15

## How To Get All Employees Under Any Perticular Manager Employee !

Jan 31, 2008

I am using SqlServer 2000 with asp.net 2.0, I have a table tbl_employees, with fields (empId, empName, empManagerId), with following data...

empId
empName
empManagerId

1
A

2
B
1

3
C
2

4
D
2

5
E
4
Now the question is that what should be the single line query or best solution if i want to get all employess under a perticular manager ?For example; Employees under 'A' are (B,C,D,E)    //(C,D,E are also indirectly under A)Emplloyess under 'B' are (C,D & E; E is also under B as his because his managwer 'D' is himself under 'B')

Jul 12, 2000

Hi, I would appreicate your opinion/ feed back about Being consultant vs Being employee.

Does consultant makes more money than an employee and why so

Ali

## Monthly Absence Calculation For Employee

May 30, 2012

I need to calculate monthly absence days for an employee using SQL Server 2008.

Need to calculate the number of absence days for each month when start and end of the absence dates are given

INPUT: 01/15/2010 05/25/2010

OUTPUT:
Jan 16
Feb 28
Mar 31
APR 30
May 25

## Find Junk Patterns In Employee Name

Jul 6, 2012

string starts with 3 digit same number
111 H,777GGG,9999 H etc

string starts with NULL

string that starts with sequential digits
123g,897 k

string that starts with sequential alphabets
abcmki12, ghimkkk, rst123 5 etc

string only one character (digit or letter)

string only has same character repeated 3 times except for OOO

string only has three characters, 1 digit and two letters or 2 digit one letter

string that has only two characters one digit and one letter

## Pull Email Address From Employee ID

Jan 28, 2014

There is a Table DISPLAY_DETAILS in which a Column - DISPLAY_NAME, which displays data in it as :

Joe Barnard(123456);Paul Johnson(114454); - Display as Name(Employee Id).

There is a EMployee Master Table EMP_MASTER Which contains Employee Id and Email Address Columns.

From this: Joe Barnard(123456);Paul Johnson(114454); I need to get the Email Address for these Employee Ids - 123456 and 114454