Click here to Skip to main content
15,999,481 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am having performance data of each client in a table

having fields

clientid(varchar(20)),date(datetime), performance (number)

now what I want is, to fetch top 12 twelve record of each client on the basis of their performance.

please help..

thanks in advance
Posted
Comments
RDBurmon 8-Jun-12 8:27am    
Thanks Everyone who replied to this thread , So OP, I think you have got enough response and you should be able to mark it as your answer and close the thread.

Try this:
SQL
SELECT a.* FROM articles AS a
  LEFT JOIN articles AS a2
    ON a.section = a2.section AND a.article_date <= a2.article_date
GROUP BY a.article_id
HAVING COUNT(*) <= 12;
 
Share this answer
 
Tested query
SQL
SELECT DISTINCT TOP 12(Clientid), MAX(Performance) AS MAX_PerformanceOfClient FROM [TableName]
GROUP BY Clientid
ORDER BY MAX(Performance) DESC
 
Share this answer
 
Try this statement
SQL
select distinct top 12 (clientid), performance from tableName
Order By performance desc

Regards,
T
 
Share this answer
 
v3
Comments
Prasad_Kulkarni 4-Jun-12 7:48am    
I think you miss'd table name..
kodeLogic 4-Jun-12 7:53am    
Thank you, i've corrected it.
Prasad_Kulkarni 4-Jun-12 8:27am    
Good!
djrocks0101 4-Jun-12 8:14am    
its fetching 12 records of one client only..I need 12 records from each client..
Hi ,

Try this code

SQL
SELECT ClientId,Performance,Date  FROM
( SELECT ROW_NUMBER() OVER (PARTITION BY Performance ORDER BY ClientD DESC) AS 'RowNumber',
CleintId,Performance,Date FROM @tempContacts) dt WHERE
dt.RowNumber <=12 ORDER BY Performance,CleintId.



Regards

Damu
 
Share this answer
 
v3

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