'Window function syntax error at over clause

I'm solving a hackerrank SQL problem which you can see [here][1] and I have already solved it using some other method but I want to try the window function for the same, so I have run a basic query to understand the window function.

SELECT salary, SUM(salary) OVER (ORDER BY salary) AS running_total
FROM Employee;

but I got the below error.

ERROR 1064 (42000) at line 4: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(ORDER BY salary) AS running_total FROM employee' at line 2

I'm pretty confused why it's throwing an error. P.S: the query I posted above is not solving the problem, it's just a try to understand the window function, if you can solve the whole problem using the window function and write it in the answer that also will help me learn more. if you need any more details please mention them in the comments.

Table name- Employee
columns:
employee_id-> integer
name-> string
months-> integer
salary-> integer

Mysql version - 8.0.20 [1]: https://www.hackerrank.com/challenges/earnings-of-employees/problem?isFullScreen=true



Solution 1:[1]

Most likely, your MySQL version is less than 8+, and therefore does not support window functions. Here is an alternative to your current query which should run on your MySQL version:

SELECT
    salary,
    (SELECT SUM(e2.salary) FROM Employee e2
     WHERE e2.salary <= e1.salary) AS running_total
FROM Employee e1
ORDER BY salary;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tim Biegeleisen