Click here to Skip to main content
15,914,500 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
I have a table like this

id Name Percent
1 a 40
2 b 60
3 c 60
4 d 60
5 e 50
6 f 70
8 g 80

In this Table i want to select max three percentage and after that the i want to select the name for that that three max percentage which has name more than one time for same percentage
pls suggest
thanks in advance
Posted
Comments
Eduard Keilholz 18-Mar-11 7:07am    
I don't understand your question, but to select three percent of a table use :
SELECT TOP 3 PERCENT id, Name, Percent FROM TableName
Albin Abel 18-Mar-11 7:10am    
Yes, You can use ORDER BY PERCENT in addition to Eduard's answer, if you want to sort to get the percentage in order. What else you are thinking of?

select top 3 id, name, percent from mytable order by percent desc
 
Share this answer
 
v2
Try this:

SQL
select  *
from    MyTable a
where   (select count(distinct [Percent]) from MyTable where [Percent]>=a.[Percent])<=3
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900