以下语法在Postgresql中可以正常工作:
SELECT
rev_count.RevName,
rev_count.MovTitle
FROM
(SELECT
rev.name as RevName,
m.title as MovTitle,
rat.stars as OrginalRat,
rat.ratingDate as RatingDate,
count(rat.stars) OVER (PARTITION BY rev.name, m.title) as RevCount,
lead(rat.stars, 1) OVER (PARTITION BY rev.name, m.title ORDER BY rat.ratingDate) as NewRat
FROM
rating as rat
LEFT JOIN
reviewer as rev
ON
rat.rid = rev.rid
LEFT JOIN
movie as m
ON
rat.mid = m.mid) as rev_count
WHERE
rev_count.RevCount = 2
AND rev_count.NewRat IS NOT NULL
AND rev_count.NewRat > rev_count.OrginalRat
但是我在SQLite中收到以下错误: 未捕获的错误:“(”附近:语法错误
这是为什么的任何线索?我怀疑这与Aliasing有关,但不确定问题出在哪里。
答案 0 :(得分:0)
您的查询通常存在语法错误,因此根本无法使用。
您可以在此处检查语法:
https://www.eversql.com/sql-syntax-check-validator/
SQLite
不支持db引擎中的某些功能,例如PostreSQL或mySQL。有关详细信息,请参阅文档。
答案 1 :(得分:0)
此查询在SQLite 3.25.0中可以正常工作。 (早期版本还没有窗口功能。)