In order to receive a rapid answer to your question, it is beholden on you to present your table definition(s), sample data and required answer(s), in a readily consumable format. In other words you should help those who can and will help you.
To do this please click on the first link in my signature block ... the article that will be displayed contains T-SQL statements and instructions in their use ... to make it easy and quick for you to help those who wish to help you.