0

有没有办法重建dense_rankSybase ASE 中的功能?

所以我需要每个元组(foo,bar)都有一个唯一的数字。

桌子:

+-----+-----+
| foo | bar |
+-----+-----+
| a   | a   |
| a   | b   |
| a   | c   |
| a   | c   |
| b   | a   |
| b   | a   |
+-----+-----+

结果:

+-----+-----+------+
| foo | bar | rank |
+-----+-----+------+
| a   | a   |    1 |
| a   | b   |    2 |
| a   | c   |    3 |
| a   | c   |    3 |
| b   | a   |    4 |
| b   | a   |    4 |
+-----+-----+------+

没有这个功能我怎么能做到这一点dense_rank

非常感谢!

4

1 回答 1

2

以下子查询应提供相同的功能:

select t.*,
       (select 1 + count(distinct foo + ':' + bar)
        from table t2
        where t2.foo < t.foo or
              t2.foo = t.foo and t2.bar < t.bar
       ) as rank
from table t;
于 2014-10-20T10:45:50.117 回答