By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE "results" ("player" INTEGER, "tournament" INTEGER, "year" INTEGER, "course" INTEGER,"round" INTEGER, "score" INTEGER);
✓
INSERT INTO results VALUES
('1', '33', '2016', '895', '1', '20'),
('2', '33', '2016', '895', '1', '12'),
('3', '33', '2016', '895', '1', '25'),
('4', '33', '2016', '895', '1', '28'),
('7', '33', '2016', '895', '1', '25'),
('8', '33', '2016', '895', '1', '17'),
('9', '33', '2016', '895', '1', '12');
✓
SELECT *,
CASE WHEN COUNT(*) OVER (PARTITION BY tournament, year, course, round, score) > 1 THEN 'T' ELSE '' END ||
DENSE_RANK() OVER (PARTITION BY tournament, year, course, round ORDER BY score DESC) AS ranking
FROM results
ORDER BY player;
player | tournament | year | course | round | score | ranking |
---|---|---|---|---|---|---|
1 | 33 | 2016 | 895 | 1 | 20 | 3 |
2 | 33 | 2016 | 895 | 1 | 12 | T5 |
3 | 33 | 2016 | 895 | 1 | 25 | T2 |
4 | 33 | 2016 | 895 | 1 | 28 | 1 |
7 | 33 | 2016 | 895 | 1 | 25 | T2 |
8 | 33 | 2016 | 895 | 1 | 17 | 4 |
9 | 33 | 2016 | 895 | 1 | 12 | T5 |