没有分区的查询或像 rank() 这样的函数

Query without partition by or functions like rank()

假设我们有 table 个学生(姓名、年级、组别、年份) 我们想要一个查询,为每个组对应的学生排名。 我知道这可以通过 rank() OVER 轻松完成(按组排序按等级 DESC 分区)。但我认为这也可以通过自连接或子查询来完成。有什么想法吗?

等价于rank()是:

select s.*,
       (select 1 + count(*)
        from students s2
        where s2.group = s.group and
              s2.grade > s.grade
       ) as rank
from students s;