> did I show you the diagram of my tables? did you see it?
> explain to me in code, giving an example of the whole question
I'm afraid that is beyond the scope of a forum interaction. If you have a specific question or issue we can answer it or point you in the right direction. We cannot simply provide you with your specific solution based upon fragments of information. You should continue to write out the pseudo code for your problem and then translate into procedure sql.