count distinct values in a column given a constraint from another column using over clause in ssms