当我尝试运行以下代码时,出现此错误:missing FROM-clause entry for table "photos_cateogry"
photos = Photo.objects.all().extra(
select={
'sort_count':
"""
(SELECT COUNT('id') FROM comments_comment WHERE comments_comment.photo_id=photos_cateogry.id) +
(SELECT COUNT('likers') FROM photos_category WHERE photos_category.photo_id=photos_category.id)
"""
}
)
有人会对如何解决这个问题有任何想法吗?
答案 0 :(得分:0)
您可能错过了photos_category
子句
FROM
表
photos = Photo.objects.all().extra(
select={
'sort_count':
"""
(SELECT COUNT('id') FROM comments_comment,photos_category WHERE comments_comment.photo_id=photos_category.id) +
(SELECT COUNT('likers') FROM photos_category WHERE photos_category.photo_id=photos_category.id)
"""
}
)