• I'm not sure what you need. I couldn't understand. It would help a lot if you posted table definitions (DDL statements), sample data (Insert statements) and expected output based on that sample data.

    Read the article on my signature for guidance on how to do it.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2