python-3.x - Peewee 3 - Python - 排名查询结果
问题描述
我有一个带有注释(id、title、parent)的自引用数据库表。
[注意:表格的自引用属性与问题无关]
我想按标题的字母顺序对它们进行排序,并通过id
. 我使用 Peewee 3 作为 ORM。
数据库型号:
class Note(Model):
title = CharField()
parent = ForeignKeyField('self', backref='children', null = True)
代码:
noteAlias = Note.alias()
subquery = (noteAlias.select(noteAlias.id, fn.RANK().over(partition_by=[noteAlias.title], order_by=[noteAlias.title]).alias('rank')).where(noteAlias.parent.is_null()).alias('subq'))
query = (Note.select(subquery.c.id, subquery.c.rank).from_(subquery).where(subquery.c.id == 5))
print("Rank of element is: " + str(query.rank))
这段代码给了我以下错误:
cursor.execute(sql, params or ())
sqlite3.OperationalError: near "(": syntax error
SQLite 测试
如果我直接对我的数据库运行这个 sqlite 代码:
SELECT (title, ROW_NUMBER() OVER (ORDER BY title) AS placement) FROM note
我得到错误:near ",": syntax error:
解决方案
您的 SQLite 版本可能不支持窗口函数,因为我相信这是最近在 3.25 中添加的。
推荐阅读
- reactjs - React Hook UseEffect 结合 Firebase 创建无限循环
- r - 如何将 dplyr summarise_all 结构内的 1 个函数中的多个值导出到结果表中的列
- android - 如何在 exo 播放器的媒体源列表中设置特定索引?
- node.js - 在 Angular 5 中创建构建时出错
- python - “selenium webdriverwait class”语法错误这段代码有什么问题吗?
- proxy - 如何使用 alfresco“配置 SSL”在 debian 中配置代理
- sql-server - 需要在 SQL Server 中动态更改视图中的 Databasename
- laravel - laravel:控制器已经存在
- wordpress - 向单个 CPT 页面添加分类术语会从常规页面中删除正文类
- android - 如何在android TextView中获取单击范围的x,y位置?