It needs kind of presentation that what's your data and what you want as a final output. Furthermore AFA I understood the problem I think you need to apply groupby in SQL and then after sort top 3 records among the retrieved result set. further sample data can make me more clear regarding.
Regards, Hiren. be good(Help people in CP),do good(Vote if one finds helpful) all will happen good, In case happens bad(You are getting downvote for your best try to help OP) it will be good for later after(Countered with more points by humble member). - Gita sar in context of CP. -So Guys don't care about downvote believe in you.