Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 select query help needed

Author  Topic 

spock
Starting Member

35 Posts

Posted - 2002-02-20 : 00:53:38
Hi

I have a table which has employees and their salaries and the year in a table.

table salary(
empId int,
salaryYear int,
salary int
)

i have a range table which is used to find out the different ranges of salaries.

table range(
rangeId int,
rangePosition int,
rangeStart int,
rangeEnd int)

which has values like

1 1 0 1000
1 2 1001 2000
1 3 2001 3000....

i want to find out the number of employees in each salary range for a given year ? i cannot hardcode the ranges in the query . how do i do it ?

thanks
kaushik



Edited by - spock on 02/20/2002 00:55:43

byrmol
Shed Building SQL Farmer

1591 Posts

Posted - 2002-02-20 : 01:32:39
Spock,

Something like...



Select Count(*) as Total, R.RangeStart, R.RangeEnd from Salary S
inner join Range R on S.Salary between R.RangeStart and RangeEnd
group by R.RangeStart, R.RangeEnd



DavidM

Tomorrow is the same day as Today was the day before.

Edited by - byrmol on 02/20/2002 01:33:18
Go to Top of Page

spock
Starting Member

35 Posts

Posted - 2002-02-20 : 02:55:33
Thanks David

that worked perfectly !

kaushik

Go to Top of Page
   

- Advertisement -