select distinct a.pattern ,convert(numeric(18,0) ,isnull(b.[DCount]as [DCount]
,DENSE_RANK () OVER ( Partition by a.pattern order by b.[DCount]desc ) as [Rank]
from a, b
Дает вывод как
Pattern Dcount Rank
A 0 1
A 0 1
A 0 2
A 0 2
B 0 2
B 0 2
B 0 2
B 0 2
C 0 2
C 0 2
C 0 2
В то время как требуемый вывод
Pattern Dcount Rank
A 0 1
A 0 1
A 0 1
A 0 1
B 0 1
B 0 1
B 0 1
B 0 1
C 0 1
C 0 1
C 0 1