以下是我所拥有的
userid score 1 8 2 5 3 4 4 4 5 10 6 3
我想要的是如下
userid score position 5 10 1 1 8 2 2 5 3 3 4 4 4 4 4 6 3 5
注意:
我在输出下面创建的代码,
userid score position 5 10 1 1 8 2 2 5 3 3 4 4 4 4 4 6 3 6
代码是
SELECT userid, score, (SELECT COUNT(*) FROM fschema.mytab3 u2 WHERE u2.score > u1.score) + 1 AS position FROM fschema.mytab3 u1 ORDER BY position
我希望用户6具有positionas 5而不是6
position
5
6
那这个呢?
SELECT userid, score, (SELECT COUNT(distinct u2.score) FROM fschema.mytab3 u2 WHERE u2.score > u1.score) + 1 AS position FROM fschema.mytab3 u1 ORDER BY position