问题描述:写一个查询来排名价格,如果有一个领带显示相同的等级
表价格
| Id | price |
| 1 | 3.00 |
| 2 | 3.65 |
| 3 | 4.00 |
| 4 | 3.00 |
| 5 | 4.00 |
正确的结果:
| price | Rank |
| 4.00 | 1 |
| 4.00 | 1 |
| 3.65 | 2 |
| 3.00 | 3 |
| 3.00 | 3 |
问题:
我的查询如下,但我没有得到正确的排名
SELECT B.price, (SELECT COUNT(A.price) FROM price A
WHERE A.price >= B.price) AS rank
FROM price B
ORDER BY B.price DESC;
答案 0 :(得分:0)
试试这个......
SELECT B.price, dense_rank() over (ORDER BY B.price DESC)
FROM price B
ORDER BY B.price DESC;