• <i id='4tS6N'><tr id='4tS6N'><dt id='4tS6N'><q id='4tS6N'><span id='4tS6N'><b id='4tS6N'><form id='4tS6N'><ins id='4tS6N'></ins><ul id='4tS6N'></ul><sub id='4tS6N'></sub></form><legend id='4tS6N'></legend><bdo id='4tS6N'><pre id='4tS6N'><center id='4tS6N'></center></pre></bdo></b><th id='4tS6N'></th></span></q></dt></tr></i><div id='4tS6N'><tfoot id='4tS6N'></tfoot><dl id='4tS6N'><fieldset id='4tS6N'></fieldset></dl></div>

    1. <tfoot id='4tS6N'></tfoot>

      <small id='4tS6N'></small><noframes id='4tS6N'>

      1. <legend id='4tS6N'><style id='4tS6N'><dir id='4tS6N'><q id='4tS6N'></q></dir></style></legend>
          <bdo id='4tS6N'></bdo><ul id='4tS6N'></ul>

      2. 如何在sqlalChemical中生成子查询

        How to make a subquery in sqlalchemy(如何在sqlalChemical中生成子查询)
      3. <tfoot id='jrV8p'></tfoot>

        <small id='jrV8p'></small><noframes id='jrV8p'>

          <legend id='jrV8p'><style id='jrV8p'><dir id='jrV8p'><q id='jrV8p'></q></dir></style></legend>
              <tbody id='jrV8p'></tbody>

                  <bdo id='jrV8p'></bdo><ul id='jrV8p'></ul>
                  <i id='jrV8p'><tr id='jrV8p'><dt id='jrV8p'><q id='jrV8p'><span id='jrV8p'><b id='jrV8p'><form id='jrV8p'><ins id='jrV8p'></ins><ul id='jrV8p'></ul><sub id='jrV8p'></sub></form><legend id='jrV8p'></legend><bdo id='jrV8p'><pre id='jrV8p'><center id='jrV8p'></center></pre></bdo></b><th id='jrV8p'></th></span></q></dt></tr></i><div id='jrV8p'><tfoot id='jrV8p'></tfoot><dl id='jrV8p'><fieldset id='jrV8p'></fieldset></dl></div>
                  本文介绍了如何在sqlalChemical中生成子查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  SELECT *
                  FROM Residents
                  WHERE apartment_id IN (SELECT ID
                                         FROM Apartments
                                         WHERE postcode = 2000)
                  

                  我正在使用sqlalChemy并尝试执行上面的查询。我一直无法使用db.engine.execute(sql)将其作为原始SQL执行,因为它抱怨我的关系不存在.但是我使用以下格式成功地查询了我的数据库:session.Query(Residents).filter_by(???)。 不过,我想不出如何使用此格式构建我想要的查询。

                  推荐答案

                  可以使用subquery方法创建子查询

                  subquery = session.query(Apartments.id).filter(Apartments.postcode==2000).subquery()
                  query = session.query(Residents).filter(Residents.apartment_id.in_(subquery))
                  

                  这篇关于如何在sqlalChemical中生成子查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)
                  Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)
                  Is there a way of group by month in Pandas starting at specific day number?( pandas 有从特定日期开始的按月分组的方式吗?)
                  Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)
                  Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)
                  Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)
                • <legend id='xpLek'><style id='xpLek'><dir id='xpLek'><q id='xpLek'></q></dir></style></legend>
                    <tbody id='xpLek'></tbody>

                    <i id='xpLek'><tr id='xpLek'><dt id='xpLek'><q id='xpLek'><span id='xpLek'><b id='xpLek'><form id='xpLek'><ins id='xpLek'></ins><ul id='xpLek'></ul><sub id='xpLek'></sub></form><legend id='xpLek'></legend><bdo id='xpLek'><pre id='xpLek'><center id='xpLek'></center></pre></bdo></b><th id='xpLek'></th></span></q></dt></tr></i><div id='xpLek'><tfoot id='xpLek'></tfoot><dl id='xpLek'><fieldset id='xpLek'></fieldset></dl></div>
                      <bdo id='xpLek'></bdo><ul id='xpLek'></ul>
                        <tfoot id='xpLek'></tfoot>

                      1. <small id='xpLek'></small><noframes id='xpLek'>