Select a1, a2, count(*) from
(Select a1, a2 from table where a <= b
Select a2, a1 from table where b < a) as abc
group by a1, a2
Basically, i have picked the rows in which first column value is greater than second value and then i picked the rest of rows by changing first and second columns. Now the order of columns is same and i have simply grouped the rows on the basis of these two columns.