是否可以在 django 中进行以下 sql 查询
select * from (
select * from users
) order by id
这只是最小的例子。我有一个很长的子查询而不是select * from users. 但我不明白如何将它插入子查询。
更新:来自doc的子查询不适合,因为它构建了以下请求
SELECT "post"."id", (
SELECT U0."email"
FROM "comment" U0
WHERE U0."post_id" = ("post"."id")
ORDER BY U0."created_at" DESC LIMIT 1
) AS "newest_commenter_email" FROM "post"
并且这个子查询只能返回一个值(.values('email'))。建设select (subquery) as value from table代替select value from (subquery)
Qyouu
三国纷争
相关分类