Nidutt
Nidutt

Reputation: 315

Rank Function in SQL 5.6.10

I need to apply a Rank function in MYSQL 5.6.10. The issue is, I am getting a syntax error when i am using the standard syntax i found online

Eg:

INSERT INTO t(val)
VALUES(1),(2),(2),(3),(4),(4),(5);

SELECT
    val,
    RANK() OVER (
        ORDER BY val
    ) my_rank
FROM
    t;

I am getting a red line suggesting a syntax error near 'OVER ('

Upvotes: 1

Views: 249

Answers (2)

ismetguzelgun
ismetguzelgun

Reputation: 1105

As far as i know window functions are introduced after version 8 and above. source

Something like this may give you some insights.

SELECT
    val,
    (select 1+count(*) from t b where t.val>b.val)"rank"
FROM
    t;

Demo

Upvotes: 1

danblack
danblack

Reputation: 14666

RANK is only available in MySQL-8.0+

Upvotes: 1

Related Questions