Hi Sateesh
If this is a homework question, please post what you've tried so we can see you've made an effort. 
In any case, please post some sample data and the result you would want for that sample data.
Ryan Randall
Solutions are easy. Understanding the problem, now, that's the hard part.