There is a syntax error in the SQL query near line 1 "OVER (ORDER BY r.Id)) AS Grown FROM results AS r ORDER BY r.Id LIMIT 0.25"
P粉803527801
P粉803527801 2024-04-01 10:36:24
0
1
407

I have a SQL command that uses lag to list the data in a table and calculate it with the previous value to calculate the percentage increase. On my localhost it works but on my host it keeps giving this error and I use mysql.

CREATE TABLE `results` 
(
    `id` int(11) NOT NULL,
    `price` int(11) NOT NULL,
    `Date` date DEFAULT NULL,
    `grown` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

This is the command I use

SELECT 
    *, - 100.0 * ( 1-price/ LAG(price) OVER (ORDER BY results.id)) AS Grown 
FROM 
    results AS r 
ORDER BY 
    r.id;

P粉803527801
P粉803527801

reply all(1)
P粉395056196

You have "OVER (ORDER BY t.Id))" but no table/alias named t

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template