Raghavendra, did you ever read the The SCN Rules of Engagement? You posted this requirement four times on different posts which are not related to your requirement. You should not do this, instead open create a new question please.
Regarding your requirement. All points are already clearly described, you only have to translate it to an efficient SQL. I think you have to investigate yourself how SQL works. Otherwise you can send your customer to anyone who has the knowledge to do it w/o solving the most simple requirements with the help of a forum
.