Look at the article link in my signature, you need to post some sample data that would give ready data to test and come up with the solution.
how can we suggest the solution without knowing your table structure and your requirement (conditions).
Blog -- LearnSQLWithBru
Join on Facebook Page Facebook.comLearnSQLWithBru
Twitter -- BruMedishetty