SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseSQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old April 7th, 2004, 01:49 PM
gknuth gknuth is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 1 gknuth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #2  
Old April 8th, 2004, 04:16 AM
dip dip is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 11 dip User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

**********************************************

Reply With Quote
  #3  
Old April 8th, 2004, 08:32 AM
dip dip is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 11 dip User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
hi

if its done then plz let me know
dipit

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > Retrieve other values while using Min and Max aggregates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT