`near '(': 语法错误` 创建每个流派中畅销专辑的视图以及销售情况
此代码使用 Chinook 数据库为每个流派中的畅销专辑创建一个名为 BestSeller 的视图,并提供销售额(基于已售曲目的数量),其中包含流派、专辑、艺术家和销售额列。
CREATE VIEW vBestSellingGenreAlbum AS SELECT DISTINCT
g.Name Genre,
FIRST_VALUE(a.Title) OVER (PARTITION BY g.GenreId ORDER BY COUNT(*) DESC) Album,
FIRST_VALUE(r.Name) OVER (PARTITION BY g.GenreId ORDER BY COUNT(*) DESC) Artist,
MAX(COUNT(*)) OVER (PARTITION BY g.GenreId) Sales
FROM genres g
INNER JOIN tracks t ON t.GenreId = g.GenreId
INNER JOIN albums a ON a.AlbumId = t.AlbumId
INNER JOIN artists r ON r.ArtistId = a.ArtistId
INNER JOIN invoice_items i ON i.TrackId = t.TrackId
GROUP BY g.GenreId, a.AlbumId;
SELECT * FROM vBestSellingGenreAlbum;
我收到错误
near '(': syntax error
This code uses the Chinook database to create a view called BestSeller for the bestselling album in each genre with sales (based on the quantity of tracks sold) with the columns Genre, Album, Artist, and Sales.
CREATE VIEW vBestSellingGenreAlbum AS SELECT DISTINCT
g.Name Genre,
FIRST_VALUE(a.Title) OVER (PARTITION BY g.GenreId ORDER BY COUNT(*) DESC) Album,
FIRST_VALUE(r.Name) OVER (PARTITION BY g.GenreId ORDER BY COUNT(*) DESC) Artist,
MAX(COUNT(*)) OVER (PARTITION BY g.GenreId) Sales
FROM genres g
INNER JOIN tracks t ON t.GenreId = g.GenreId
INNER JOIN albums a ON a.AlbumId = t.AlbumId
INNER JOIN artists r ON r.ArtistId = a.ArtistId
INNER JOIN invoice_items i ON i.TrackId = t.TrackId
GROUP BY g.GenreId, a.AlbumId;
SELECT * FROM vBestSellingGenreAlbum;
I get the error
near '(': syntax error
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于 3.25.0 之前的 SQLite 版本,您可以使用 2 级聚合并利用 SQLite 的 裸列:
请参阅演示。
For versions of SQLite prior to 3.25.0, you can do it with 2 levels of aggregation and by utilizing SQLite's feature of bare columns:
See the demo.
如果您使用的是 Linux,请检查 LD_LIBRARY_PATH 中的 sqlite lib > > 3.25。
您的系统中可能安装了多个版本的 sqlite。确保
最新版本(>3.25)在 LD_LIBRARY_PATH 中具有优先权。
If you are using Linux, check your LD_LIBRARY_PATH for sqlite lib > 3.25.
More than one version of sqlite may be installed in your system. Ensure
that the recent version ( >3.25) has precedence in LD_LIBRARY_PATH.