You have expressed a requirement, but not asked a question. What would you like help with, exactly?
Please provide consumable DDL, sample data and desired results so that people can try to assist, assuming you are looking for T-SQL assistance.
If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.