blindman, your queries are starting to look good
but the join should be outdented
use foo and bar if more than one column is intended (YourColumns alone does not show comma syntax)
and shorter aliases make it easier to read

Code:
select T.foo, T.bar
from YourTable as T
inner join YourTable as Th
on T.GroupColumns = Th.GroupColumns
and T.SortColumn <= Th.SortColumn
group by T.foo, T.bar
having count(*) <= n