title: how to use group by in flask sql alchemy
body: <p>I have two tables </p>
  
  <pre><code>class MinMaxDim(db.Model):
     min_max_id = db.Column(db.Integer, primary_key=True)
     user_id = db.Column(db.Integer, nullable=False)
     room_id = db.Column(db.Integer, nullable=True)
     min_temp = db.Column(db.Integer, nullable=True)
     max_temp = db.Column(db.Integer, nullable=True)
     min_humidity = db.Column(db.Integer, nullable=True)
     max_humidity = db.Column(db.Integer, nullable=True)
     min_pressure = db.Column(db.Integer, nullable=True)
     max_pressure = db.Column(db.Integer, nullable=True)
  
  
  class AvgDim(db.Model):
    avg_id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, nullable=False)
    room_id = db.Column(db.Integer, nullable=True)
    avg_temp = db.Column(db.Integer, nullable=True)
    avg_humidity = db.Column(db.Integer, nullable=True)
    avg_pressure = db.Column(db.Integer, nullable=True)
  </code></pre>
  
  <p><strong>Requirements:</strong></p>
  
  <ul>
  <li>I will send room_id as an argument to the function, It should return the last 7 days min_temp, max_temp, and avg_temp values from the two tables.</li>
  </ul>
  
  <p><strong>What I have tried:</strong></p>
  
  <p>I have created a function in that I have used group_by function but I am getting this error:</p>
  
  <pre><code>  (psycopg2.errors.GroupingError) column "min_max_dim.min_max_id" must appear in the GROUP BY clause 
     or be used in an aggregate function
  </code></pre>
  
  <p><strong>My code</strong>:</p>
  
  <pre><code>     def get_weekly_dim_dataInfo(room_id):
          try:
             get_all_data = db.session.query(MinMaxDim).outerjoin(AvgDim, MinMaxDim.user_id ==
                             MinMaxDim.tenant_id).group_by(MinMaxDim.room_id).all()
             get_all_data_schema = MinMaxDimSchema(many=True).dump(get_all_data)
             get_all_avg_data_schema = AvgDimSchema(many=True).dump(get_all_data)
             print(get_all_data)
           except Exception as e:
               print(e)
               return False
  </code></pre>