title: sqlalchemy SELECT column FROM (SELECT columns FROM TABLE)
body: <p>I have the following query</p>
  
  <pre><code>reports = self.session.query((
          func.sum(Report.a) / func.sum(Report.b))
              .label('c'),
          Report.id,
          Report.id2
          ).group_by(Report.id, Report.id2
          )
  </code></pre>
  
  <p>I now want to get the max(c) for the reports, grouped by id.</p>
  
  <p>Essentially, I am trying to have a sqlalchemy solution to this problem
  <a href="https://stackoverflow.com/questions/7745609/sql-select-only-rows-with-max-value-on-a-column">SQL Select only rows with Max Value on a Column</a></p>
  
  <p>but with the extra requirement that I need to calculate the value column I want to have the max in as in <a href="https://stackoverflow.com/questions/7475575/selecting-max-value-from-calculated-column-in-mysql">Selecting max value from calculated column in mysql</a></p>
  
  <p>I am finding it difficult to perform a </p>
  
  <pre><code>SELECT MAX(C), id FROM (SELECT A/B AS C, id FROM TABLE) t
  </code></pre>