到目前为止,我还没能通过考试 error aggregate function calls cannot contain window function calls
我还没有找到一种方法来限制不会触发错误的联接表。
我试过了 func.count(Video.id).label('rn')
代替 func.row_number().over(partition_by=role.c.movie_id).label('rn')
这给了我一个错误: aggregate function calls cannot be nested
将actor表移动到它自己的子查询中,这就产生了错误 AttributeError: 'Alias' object has no attribute 'type'
```
sub_query = db.session.query(
func.json_build_object(
'movie_name', Movie.movie_name,
'movie_year', Movie.year,
'movie_description', Movie.description,
'Actors', func.array_agg(
func.json_build_object(
'actors_name', Actor.name,
'actors_age', Actor.age,
'rn', func.row_number().over(partition_by=role.c.movie_id).label('rn')
)
)
)
).group_by(Movie.movie_name, Movie.year, Movie.description, role.c.movie_id)
.join(role, (role.c.movie_id == Movie.id)).join(Actor, (role.c.actor_id == Actor.id)).subquery()
query = db.session.query(sub_query).filter(text('rn <= 4'))
暂无答案!
目前还没有任何答案,快来回答吧!