子查询中的 SqlAlchemy 闭包
我搜索了很多主题但没有找到答案,或者问题太复杂。那么好吧。这是我的第一个问题。 这是 SQL
SELECT parent.*,
(
SELECT COUNT(*)
FROM child
WHERE parent.id = child.parent_id
)
FROM parent
如何在 sqlalchemy 中执行此子句?
WHERE ui.invited_by = u.id
可以在收藏中复制吗? SQL 表达式 ? PS我知道可以通过group_by来完成。但我需要通过子查询。
谢谢。
I have searched many topics and didn't find the answer, or question was too complex. So okay. This is my first question.
Here is the SQL
SELECT parent.*,
(
SELECT COUNT(*)
FROM child
WHERE parent.id = child.parent_id
)
FROM parent
How to do this clause in sqlalchemy?
WHERE ui.invited_by = u.id
Can it be reproduced in collections ? sql expressions ?
P.S. I know that it can be done by group_by. But i need by subquery.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
SA 查询(使用子查询)将为您提供您想要的结果:
虽然子查询并不完全像您所描述的那样,而是类似于:
仍然不明白为什么您需要您所描述的方式的子查询。
The SA query (using subquery) will give you the results you want:
although the subquery is not exactly as you described, but rather something like:
Still do not understand why you need a sub-query the way you described though.
我在这里找到了非常棒的答案。但也太复杂了。首先我想告诉大家,sql 世界中的闭包是关联性的。
这不一样,但对我有帮助。
I find here really awesome answer. But too also too complicated. First of all i want to tell that closure in sql world is CORRELATION.
This is NOT the same but helps me.