问题
I'm unable to utilize SQLite window functions (e.g. LAG, LEAD). After some investigation it seems that this is due to the fact that SQLite database version is below 3.25.0, after which window functions were made available.
Database created using SQLite 3.30.1 version
However version 3.24.0 version displayed on this 'test' database
When queries which include window functions are tested, such as the ones provided on sqlitetutorial site: the following errors are displayed
Could you please advise how to resolve this. I would much appreciate your support on this.
SELECT CustomerId, Year, Total,
LAG (Total, 1, 0) OVER (ORDER BY Year) PreviousYearTotal
FROM CustomerInvoices
WHERE CustomerId = 4;
回答1:
Had this same issue. It looks like you're using SQLiteStudio, the latest version is 3.21 from December 2019. While your database was made in SQLite 3.30 (and your software is probably using 3.30), the version of SQLiteStudio you are using is based on 3.24.
There is an outstanding feature request to implement window functions in SQLiteStudio. Until then, the best you can do is replace the sqlite3.dll in the SQLiteStudio program directory with a newer version (3.30 , 32-bit works). Window functions will show as a syntax error, but the queries will still execute.
来源:https://stackoverflow.com/questions/59233787/using-sqlite-window-functions-and-creating-up-to-date-sqlite-version-database