gpt4 book ai didi

python - 如何在django中编写子查询

转载 作者:行者123 更新时间:2023-11-29 13:39:00 25 4
gpt4 key购买 nike

是否可以在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)

最佳答案

我会使用 python 连接器连接到 postgreSQL - http://www.postgresqltutorial.com/postgresql-python/query/,这就是我为 mysql 所做的,我认为没有尝试postgresql

关于python - 如何在django中编写子查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58209119/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com