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
 Transact-SQL (2000)
 get first row in each group and shuffle data

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-04-20 : 09:56:29
spirit1 writes "Hi.

My SQL server version:
Microsoft SQL Server 2000 - 8.00.384 (Intel X86) May 23 2001 00:02:52 Copyright (c) 1988-2000 Microsoft Corporation Desktop Engine on Windows NT 5.1 (Build 2600: Service Pack 1)

this is my problem.

result of my query from multiple tabels, joins etc (select * ... order by CompanyId, JobTitle), the query has to have selected all of the colums (there are about 15 of them.)
It looks like this:

CompanyId JobId Job Employed Applicants
1 1 title1 10 3
1 2 title2 2 1
1 5 title5 13 3
2 1 title1 6 6
2 5 title5 8 1
3 6 title6 3 2
4 1 title1 5 3
5 2 title2 6 4
5 4 title4 1 2
5 5 title5 3 2
6 2 title2 15 4


this is the result i'd like to get. other columns in original query are all data for a company, the only data that is different from row to row is JobId, Job, Employed, Applicants

CId = CompanyId
J = Job
E = Employed
A = Applicants


CId J1 E1 A1 J2 E2 A2 J3 E3 A3 Other Company data
1 title1 10 3 title2 2 1 title5 13 3
2 title1 6 6 title5 8 1
3 title6 3 2
4 title1 5 3
5 title2 6 4 title4 1 2 title5 3 2
6 title2 15 4


i got stuck on getting the first row in group from the query.

i hope it's clear what i need to do?

thanx"
   

- Advertisement -