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()
toROW_NUMBER() OVER (...) AS rn
for correct syntax in the CTE. - Specified the columns
files.idFile
andfiles.dateAdded
in the CTE selection to avoid ambiguity and because*
is not necessary for the operation. - Replaced
UPDATE CTE
withUPDATE 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
toDATE_ADD
and adjusted its syntax to match MariaDB's requirements, asDATEADD
is not a function in MariaDB.
- Public
- ·
- Wed, 13 Mar 2024 20:02:43 GMT