Got confused on how to get this requirement in a single statement without using T-SQL. Check this solution even though it is not so elegant, but works great having said what the requirement looks.