View Single Post
  #5 (permalink)  
Old March 25th, 2008, 04:04 PM
crabjoe crabjoe is offline
Authorized User
Points: 254, Level: 5
Points: 254, Level: 5 Points: 254, Level: 5 Points: 254, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2007
Location: , , .
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm trying to get this based on the Top 3 because I want the Top by Month.

MONTH NAME SAVINGS
200801 JOHN 500
200801 MIKE 250
200801 JANE 50
200802 JOHN 500
200802 SHANE 400
200802 MIKE 350
200803 JANE 700
200803 JOHN 500
200803 MARK 200

The only way I can think of doing this is using a union query such as the below.

select top 3 MONTH, NAME, SAVING from T_SAVINGS where MONTH = '200801' order by SAVING desc
union
select top 3 MONTH, NAME, SAVING from T_SAVINGS where MONTH = '200802' order by SAVING desc
union
select top 3 MONTH, NAME, SAVING from T_SAVINGS where MONTH = '200803' order by SAVING desc
etc......... for all 12 months.

I'm looking for a short cut to get the top 3 or top 10 by month.



Reply With Quote