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.

View 11 Replies


ADVERTISEMENT

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.

View 4 Replies View Related

Find Highest Marks In Student Table Query

Oct 9, 2007



Hi Everybody
I've one table named Student. Here is data







Name
Subject
Mraks





Prasad
English
80

Tushar
English
79

Sunil
English
78

Prasad
Geometry
80

Tushar
Geometry
81

Sunil
Geometry
79

Prasad
History
82

Tushar
History
81

Sunil
History
80


Now I want to write a query that displays student with subjects and marks who secured highest marks in each subject.
I want to output like this





Name
Subject
Mraks





Prasad
English
80

Tushar
Geometry
81

Prasad
History
82

So will anybody help me to write a sql query that acheive the same output

View 5 Replies View Related

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

View 3 Replies View Related

Find Highest Number

Sep 26, 2004

hello all,

i'm not new to SQL but i cant seem to get this right:
hope some one will:

how to find highest unique number of a certain column(val)for a specific name(name is in INPUT parameter)

i.e :

id | name | val
---------------
1 | name1 | 2.7
2 | name1 | 3.5
3 | name1 | 3.5
4 | name1 | 3.5
5 | name1 | 1.3
6 | name2 | 3.1
7 | name2 | 3.1
8 | name2 | 2.9

requested result:
if input param(name)=name1

result:
1 | name1 | 2.7

if input param(name)=name2

result:
8 | name2 | 2.9

hope some one can write the sql cmd for this
i'll be grateful !
thank you!

View 3 Replies View Related

How Do I Find The Highest Unique Identifier?

Sep 5, 2005

I'd like to know the current value of my uniqueID column before Icreate a new record.Is there a way to find out this value?It is numeric in my case, but I can't just look for the MAX value,since some records may have been deleted, and the value for theuniqueID still stays at the higher value.Is there a way to read this internally kept value?

View 5 Replies View Related

SQL Server 2008 :: Using Cursors To Find First / Highest And Last Values

Sep 20, 2015

I have basic knowledge of T-SQL and I am using Cursors to get the first value, the last value and the peak value and some other values from other tables. I found some examples on google but the code I am using is mixed up. I am using multiple Cursors. I need to join three tables to get the result set into the Cursor. The first example uses 2 tables.

@FirstName NVARCHAR,
@LastName NVARCHAR,
@FirstValue decimal,
@HighestValue decimal,
@LastValue decimal

-- First Cursor

DECLARE TESTCURSOR CURSOR
DYNAMIC

[Code] ....

The above code seems totally inefficient but it gives the correct result. Now I want to pull some more value and join a third table (TABLE z) in the above CURSORS and not sure how to make it working using CURSORS.I would like to use the following in the CURSORS above.

SELECT x.publishdate, y.firstname, y.lastname, y.age, z.initialValue AS FirstValue, z.HighestValue AS Highest, z.LastValue AS Last
FROM TABLE x
LEFT OUTER JOIN TABLE y
ON x.id = y.id
INNER JOIN TABLE z
ON x.id = z.id

View 9 Replies View Related

Database Of Employees - Find Highest Pay Rate For One Single Person

Jul 10, 2014

I have a database of employees and pay rates.

One employee has two pay rates for two different jobs:

Job A: Rate $10.00
Job B: Rate $15.00

I will be updating their record so that they only have one job going forward, Job C. I need Job C to equal their HIGHER of the two existing jobs.

I have a select statement to find what the higher rate is. However, I am not sure how I can apply the rate to be the new job's rate. Here's what I used to find the highest rate for one single person:

SELECT max(rate), employeeID
FROM JobsTable
inner join IDTable
on JobsID2 = IDID2

WHERE JobCode in ('JOBA','JOBB')
and EmployeeID = '12345'
GROUP BY EmployeeID

(this returns the employee ID from one table, and the highest rate from Jobs A and B from another table)

I can get it to update to add JobC -- how can I get it to assign the result from the above query to be the rate used for Job C?

View 1 Replies View Related

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...

thanks in advance

View 7 Replies View Related

Max Salary Query

Mar 19, 2007

Hi

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

thanks

asm

View 4 Replies View Related

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 ?

View 2 Replies View Related

Query Highest Entries From Database - Pls Read More.....

Feb 6, 2006

Hi folks, sorry for the poor explanation.

Im using SQL 2000

I have a database that has a column named 'Initials' in a char in field

I want to be able to return in a query the highest entries if an indiviuals initials & count from the table, so it would display some like this

Initials Count
DRT 51
AMS 49
JJJ 21
PLI 10

Hope u can help, thanks in advance

View 2 Replies View Related

Query To Return Highest TransNo Per CardNo?

Aug 14, 2013

structuring a query to give me the CurrBal per CardNo.

I have table that looks like this:

CardNo DepDate CurrBal DepAmnt TransNo
1 2013-06-04 11:50 AM 79 0 6
2 2013-08-05 15:34 PM 52 100 41
2 2013-08-05 14:11 PM -48 0 40
3 2013-07-09 13:52 PM 49 0 12
3 2013-07-22 13:51 PM 11 0 14
1 2013-06-12 10:46 AM 63 0 7
3 2013-07-15 14:04 PM 33 0 13
2 2013-08-06 15:05 PM 39 0 42
2 2013-08-07 13:38 PM 30 0 43

I am looking to order this table by CardNo and then TransNo but i only want the query to display the record with the highest TransNo for each CardNo. In other words discard the records with the lower TransNo for each CardNo.

My desired result should hopefully look something like this:

CardNo DepDate CurrBal DepAmnt TransNo
1 2013-06-12 10:46 AM 63 0 7
2 2013-08-07 13:38 PM 30 0 43
3 2013-07-22 13:51 PM 11 0 14

I am using SQL 2012 Express but would also like this query to work in SQL 2005.

View 7 Replies View Related

SQL Query - Highest Rated Or Least Voted Items

Jul 23, 2005

Hello everyone,I'm trying to solve this problem but can't seem to figure out how tostart. I would like to create a rating system where people can vote(1-5 stars) on randomly displayed items. The randomly displayed itemsshould either have very high ratings OR a very low number of ratings.For example, only return items in the top 20th percentile *OR* itemswith fewer than 5 votes.The question is, how would I write an SQL query to return such aresult? Is it even possible? Should this be handled by my applicationrather than the database?For simplicity, let's assume I have the following table:tbl_items-----------------item_iditem_nameavg_ratingnum_votes-----------------Any help or pointers in the right direction would be greatlyappreciated. My apologies in advance if the solution is obvious and Iam clearly missing the point ;-)

View 5 Replies View Related

Scripts To Find Locks In SQLServer

Nov 14, 2003

Hello,

I'm writing a script to finds locks in SQLServer, but as I'm not a great SQLServer developper, I need a little help with my last procedure (see below).

I can't use a variable nor in a FROM clause nor with a USE command.

Has someone an idee how to resilve it !


-- DECLARE @DBname varchar(100)
-- DECLARE @OBJname varchar(100)
--
-- DECLARE LockedObjects CURSOR FOR
-- SELECT distinct db.name,
-- rsc_objid
-- FROM master.dbo.syslockinfo,
-- master.dbo.spt_values v,
-- master.dbo.spt_values x,
-- master.dbo.spt_values u,
-- master.dbo.sysdatabases db,
-- master.dbo.sysprocesses pdid
-- WHERE req_spid in (SELECT spid
-- FROM master.dbo.sysprocesses
-- WHERE spid IN (SELECT blocked FROM master.dbo.sysprocesses)
-- AND blocked = 0)
-- AND master.dbo.syslockinfo.rsc_type = v.number
-- AND v.type = 'LR'
-- AND master.dbo.syslockinfo.req_status = x.number
-- AND x.type = 'LS'
-- AND master.dbo.syslockinfo.req_mode + 1 = u.number
-- AND u.type = 'L'
-- AND db.dbid = rsc_dbid
-- AND req_spid = pdid.spid
--
-- OPEN LockedObjects
--
-- FETCH NEXT FROM LockedObjects
-- INTO @DBname, @OBJname
--
-- WHILE @@FETCH_STATUS = 0
-- BEGIN
--
-- SELECT id AS "Object Id",
-- name AS "Object name",
-- xtype AS "Type"
-- FROM @DBname.dbo.sysobjects
-- WHERE id = @OBJname
--
-- FETCH NEXT FROM LockedObjects
-- INTO @DBname, @OBJname
--
-- END
-- CLOSE LockedObjects
-- DEALLOCATE LockedObjects

View 1 Replies View Related

How Do I Find Out Which Version Of Express Sqlserver I Have?

Mar 9, 2008

I am not sure which one I downloaded. whether it was the one with or without "extra" analysis and reporting features.

View 5 Replies View Related

Where Can I Find Microsoft.SqlServer.Management.Smo Namespace?

Mar 2, 2008

Hello,

Where can I find the reference to Microsoft.SqlServer.Management.Smo in SQL Server 2005?

I currently have Microsoft SQL Server 2005, Microsoft SQL Native Client and Server VSS writer installed. (and ran the Service Pack 2 installer, but it doesn't want to update 'Database Services')


Thanks in advance,

Ruben Pieters

View 6 Replies View Related

SQLSERVER-The System Cannot Find The File Specified(error While Running The JOB)

May 27, 2008

Hi,

I have a SQL Server Agent job set up to run a job that calls a dts package on the server.

When I run the DTS Package manually, everything works fine and does what it is supposed to do.

When I run the job, The job fails. If somebody had this error can you please help me out

I am getting following error in my job...

DTSRun: Loading...Error: -2147287038 (80030002);
Provider Error: 0 (0)
Error string: The system cannot find the file specified. Error source: Microsoft Data Transformation Services (DTS) Package
Help file: sqldts.hlp
Help context: 713.
Process Exit Code 1. The step failed.

could you please let me know what is the possible cause for the above error.

Many Thanks,
Madhu

View 1 Replies View Related

Where Can I Find The Infamous Microsoft.SQLServer.Broker Download?

Feb 13, 2006

I've been trying to find examples on how to work with the broker using ADO.Net and haven't found much.

View 3 Replies View Related

Error: System Cannot Find The File Specified: (Microsoft.SqlServer.Express.SQLEditors)

Jan 16, 2008



I know there are already several bug submissions on this error, and I am sure the cryptoAPI team is working to resolve this issue.. However... Is it possible that the CAPICOM update (KB931906) could have contributed to this issue? In my instance, I installed SQLServer 2005 Express w/ Adv Tools SP2 after a freash XP install. I checked it out, and everything worked fine. I updated windows (online) and now it gives this error. In fact, I cannot even run the un-install because the setup utility also hits the following error (as taken from the log file):


Microsoft SQL Server 2005 Setup beginning at Wed Jan 16 12:47:35 2008
Process ID : 576
d:97352a1d146f8bca5542016500a05210setup.exe Version: 2005.90.3042.0
Running: LoadResourcesAction at: 2008/0/16 12:47:35
Complete: LoadResourcesAction at: 2008/0/16 12:47:35, returned true
Running: ParseBootstrapOptionsAction at: 2008/0/16 12:47:35
Loaded DLL:97352a1d146f8bca5542016500a05210xmlrw.dll Version:2.0.3609.0
Complete: ParseBootstrapOptionsAction at: 2008/0/16 12:47:35, returned false
Error: Action "ParseBootstrapOptionsAction" failed during execution. Error information reported during run:
Could not parse command line due to datastore exception.
Source File Name: utillibpersisthelpers.cpp
Compiler Timestamp: Wed Jun 14 16:30:14 2006
Function Name: writeEncryptedString
Source Line Number: 124
----------------------------------------------------------
writeEncryptedString() failed
Source File Name: utillibpersisthelpers.cpp
Compiler Timestamp: Wed Jun 14 16:30:14 2006
Function Name: writeEncryptedString
Source Line Number: 123
----------------------------------------------------------
Error Code: 0x80070002 (2)
Windows Error Text: The system cannot find the file specified.

Source File Name: cryptohelpercryptsameusersamemachine.cpp
Compiler Timestamp: Wed Jun 14 16:28:04 2006
Function Name: sqls::CryptSameUserSameMachine:rotectData
Source Line Number: 50

2
Could not skip Component update due to datastore exception.
Source File Name: datastorecachedpropertycollection.cpp
Compiler Timestamp: Wed Jun 14 16:27:59 2006
Function Name: CachedPropertyCollection::findProperty
Source Line Number: 130
----------------------------------------------------------
Failed to find property "InstallMediaPath" {"SetupBootstrapOptionsScope", "", "576"} in cache
Source File Name: datastorepropertycollection.cpp
Compiler Timestamp: Wed Jun 14 16:28:01 2006
Function Name: SetupBootstrapOptionsScope.InstallMediaPath
Source Line Number: 44
----------------------------------------------------------
No collector registered for scope: "SetupBootstrapOptionsScope"
Running: ValidateWinNTAction at: 2008/0/16 12:47:35
Complete: ValidateWinNTAction at: 2008/0/16 12:47:35, returned true
Running: ValidateMinOSAction at: 2008/0/16 12:47:35
Complete: ValidateMinOSAction at: 2008/0/16 12:47:35, returned true
Running: PerformSCCAction at: 2008/0/16 12:47:35
Complete: PerformSCCAction at: 2008/0/16 12:47:35, returned true
Running: ActivateLoggingAction at: 2008/0/16 12:47:35
Error: Action "ActivateLoggingAction" threw an exception during execution. Error information reported during run:
Datastore exception while trying to write logging properties.
Source File Name: datastorecachedpropertycollection.cpp
Compiler Timestamp: Wed Jun 14 16:27:59 2006
Function Name: CachedPropertyCollection::findProperty
Source Line Number: 130
----------------------------------------------------------
Failed to find property "primaryLogFiles" {"SetupStateScope", "", ""} in cache
Source File Name: datastorepropertycollection.cpp
Compiler Timestamp: Wed Jun 14 16:28:01 2006
Function Name: SetupStateScope.primaryLogFiles
Source Line Number: 44
----------------------------------------------------------
No collector registered for scope: "SetupStateScope"
00E2CFC0Unable to proceed with setup, there was a command line parsing error. : 2
Error Code: 0x80070002 (2)
Windows Error Text: The system cannot find the file specified.

Source File Name: datastorepropertycollection.cpp
Compiler Timestamp: Wed Jun 14 16:28:01 2006
Function Name: SetupBootstrapOptionsScope.InstallMediaPath
Source Line Number: 44

Failed to create CAB file due to datastore exception
Source File Name: datastorecachedpropertycollection.cpp
Compiler Timestamp: Wed Jun 14 16:27:59 2006
Function Name: CachedPropertyCollection::findProperty
Source Line Number: 130
----------------------------------------------------------
Failed to find property "HostSetup" {"SetupBootstrapOptionsScope", "", "576"} in cache
Source File Name: datastorepropertycollection.cpp
Compiler Timestamp: Wed Jun 14 16:28:01 2006
Function Name: SetupBootstrapOptionsScope.HostSetup
Source Line Number: 44
----------------------------------------------------------
No collector registered for scope: "SetupBootstrapOptionsScope"
Message pump returning: 2

Since the Microsoft.SqlServer.Express.SQLEditors utilizes a crypto wrapper, givin the error above... would the CAPICOM update have affected things?

Brian Nichols

View 1 Replies View Related

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?

View 8 Replies View Related

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?

View 15 Replies View Related

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)

View 20 Replies View Related

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.

View 1 Replies View Related

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 ?

View 3 Replies View Related

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

View 4 Replies View Related

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

View 13 Replies View Related

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

View 2 Replies View Related

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

View 2 Replies View Related

TRigger To Increment Salary By 10%

Sep 26, 2007

aa

View 12 Replies View Related

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,1500then my query return me 1500,1300,1200 whereas i want to 1500,1300,1300,1200
how can i do it
please help
thanks 
  

View 1 Replies View Related

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;

View 1 Replies View Related

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.

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved