Home  >  Q&A  >  body text

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"

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粉803527801P粉803527801182 days ago260

reply all(1)I'll reply

  • P粉395056196

    P粉3950561962024-04-02 00:49:45

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

    reply
    0
  • Cancelreply