|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Retrieve other values while using Min and Max aggregates
Hi all. I tried to search the forum for this, but I'm not entirely sure how to phrase it to get the best results, so I figured I'd post and hope someone can help me out.
I've got a SQL statment that retrieves the minimum and maximum values from the Score field in a table called Scores (original, I know). What I'd like to do is retreive another field called PersonID for each of the two results I get. Basically, I'd like to have the output look like this: Record Score_Min Score_Min_PersonID Score_Max Score_Max_PersonID 1 ........41...........5.......................... 69............3 The current SQL statement I have is below, and works great for returning only the min and max scores. SELECT Score_Min=MIN(dbo.Scores.Score), Score_Max=MAX(dbo.Scores.Score) FROM dbo.Scores WHERE Score <> 0 Thanks in advance for your help. Gabe Last edited by gknuth : April 7th, 2004 at 01:52 PM. |
|
#2
|
|||
|
|||
|
hi
Hello,
Friend sorry to say u but, u didn’t send me the picture to ur table. Any way I assumed that personID is in same table. I think if assumption is ok it should work dipit code ********************************************** select 1 as Record , min(dbo.Scores.Score) as Score_Min , (select dbo.Scores.PersonID from Scores where dbo.Scores.Score = (select min(dbo.Scores.Score) from Scores) )as Score_Min_PersonID , max(dbo.Scores.Score)as Score_Max , (select dbo.Scores.PersonID from Scores where dbo.Scores.Score = (select max(dbo.Scores.Score) from Scores) )as Score_Max_PersonID from Scores ********************************************** |
|
#3
|
|||
|
|||
|
hi
if its done then plz let me know
dipit |
![]() |
| Viewing: ASP Free Forums > Database > SQL Development > Retrieve other values while using Min and Max aggregates |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|