Can't help you without doing your job and, I'm not doing your job.

This is a logic issue, not an Oracle issue.

You have to design the logic you are going to use to solve the problem, then you look at what tools Oracle offers you to implement your solution.

Think, research. If you can't come out with an idea google it.