Re: Getting values from other fields using min & max aggregates
From: Vishal Parkar (REMOVE_THIS_vgparkar_at_yahoo.co.in)
Date: 04/07/04
- Next message: Vishal Parkar: "Re: Deleting Model, MSDBData, Master Databases"
- Previous message: Carl: "Deleting Model, MSDBData, Master Databases"
- In reply to: Gabe Knuth: "Getting values from other fields using min & max aggregates"
- Next in thread: Gabe Knuth: "Re: Getting values from other fields using min & max aggregates"
- Reply: Gabe Knuth: "Re: Getting values from other fields using min & max aggregates"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 8 Apr 2004 01:09:16 +0530
Try:
SELECT Score_Min=MIN(b.Score),
Score_Min_PersonID=(select personid from Scores a
where a.score = min(b.score)),
Score_Max=MAX(b.Score),
Score_Max_PersonID=(select personid from Scores a
where a.score = max(b.score))
FROM dbo.Scores b
WHERE Score <> 0
Make sure that you have only one row for each of the max(score) and min(score) otherwise you
will get an error as
"Subquery returned more than 1 value......."
-- Vishal Parkar vgparkar@yahoo.co.in
- Next message: Vishal Parkar: "Re: Deleting Model, MSDBData, Master Databases"
- Previous message: Carl: "Deleting Model, MSDBData, Master Databases"
- In reply to: Gabe Knuth: "Getting values from other fields using min & max aggregates"
- Next in thread: Gabe Knuth: "Re: Getting values from other fields using min & max aggregates"
- Reply: Gabe Knuth: "Re: Getting values from other fields using min & max aggregates"
- Messages sorted by: [ date ] [ thread ]