SQLAI.ai

WITH CTE AS ( SELECT *, rn = ROW_NUMBER() OVER (ORDER BY strFilename ASC) FROM files INNER JOIN movie ON files.idFile = movie.idFile ) UPDATE CTE SET files.dateAdded = DATEADD(SECOND, CTE.rn, '2024-03-13 08:00:00');

            
WITH CTE AS ( SELECT files.idFile, files.dateAdded, ROW_NUMBER() OVER ( ORDER BY files.strFilename ASC ) AS rn FROM files INNER JOIN movie ON files.idFile = movie.idFile ) UPDATE files JOIN CTE ON files.idFile = CTE.idFile SET files.dateAdded = DATE_ADD('2024-03-13 08:00:00', INTERVAL CTE.rn SECOND);

Fixes:

  • Changed rn = ROW_NUMBER() to ROW_NUMBER() OVER (...) AS rn for correct syntax in the CTE.
  • Specified the columns files.idFile and files.dateAdded in the CTE selection to avoid ambiguity and because * is not necessary for the operation.
  • Replaced UPDATE CTE with UPDATE files JOIN CTE ON files.idFile = CTE.idFile because you cannot directly update a CTE. Instead, you join the CTE with the original table and update the table.
  • Changed DATEADD to DATE_ADD and adjusted its syntax to match MariaDB's requirements, as DATEADD is not a function in MariaDB.
  • Public
  • ·
  • Wed, 13 Mar 2024 20:02:43 GMT