[PYTHON] group_by with sqlalchemy and sum

When Poko wants to group_by with Poko.date as a Model and sum the pv column

from sqlalchemy import func
q = session.query(Poko.date, func.sum(Poko.pv)).group_by(Poko.date)

so

for date, sum_pv in q:
	print date, sum_pv

Can be used with tuples like

where when you want to

q = session.query(Poko.id, Poko.date, func.sum(Poko.pv)).filter_by(id=1).group_by(Poko.date)

like

When you want to group_by with multiple

q = session.query(Poko.id, Poko.date, func.sum(Poko.pv)).group_by(Poko.date, Poko.id)

And

Recommended Posts

group_by with sqlalchemy and sum
Using Sessions and Reflections with SQLAlchemy
list and sum
Use SQLAlchemy and multiprocessing
Use Enums with SQLAlchemy
With and without WSGI
With me, cp, and Subprocess
Programming with Python and Tkinter
Get table dynamically with sqlalchemy
Encryption and decryption with Python
Working with tkinter and mouse
Use DATE_FORMAT with SQLAlchemy filter
Solve with Ruby and Python AtCoder ABC133 D Cumulative sum
Cumulative sum and potato method
Introduction to RDB with sqlalchemy Ⅰ
How to update with SQLAlchemy?
Browse columns encrypted with sqlalchemy
python metaclass and sqlalchemy declareative
How to Alter with SQLAlchemy?
Super-resolution with SRGAN and ESRGAN
python with pyenv and venv
Support multi session with SQLAlchemy
How to Delete with SQLAlchemy?
With me, NER and Flair
Works with Python and R
Get data from MySQL on a VPS with Python 3 and SQLAlchemy
Solve with Ruby, Python and Java AtCoder ARC104 B Cumulative sum
Addicted to character code by inserting and extracting data with SQLAlchemy
Communicate with FX-5204PS with Python and PyUSB
Interactive visualization with ipywidgets and Bokeh
Shining life with Python and OpenCV
Python-Mouse and keyboard operation with pyautogui
Sorting with mixed numbers and letters
Use Azure SQL Database with SQLAlchemy
Robot running with Arduino and python
Install Python 2.7.9 and Python 3.4.x with pip.
Difference between SQLAlchemy filter () and filter_by ()
AM modulation and demodulation with python
[Python] font family and font with matplotlib
Connect to multiple databases with SQLAlchemy
Easy Slackbot with Docker and Errbot
Accelerate query generation with SQLAlchemy ORM
Image segmentation with scikit-image and scikit-learn
Authentication process with gRPC and Firebase Authentication
Scraping with Python, Selenium and Chromedriver
Play with Poincare series and SymPy
HTTPS with Django and Let's Encrypt
Photo segmentation and clustering with DBSCAN
Scraping with Python and Beautiful Soup
Combining polymorphic inheritance with many-to-many with SQLAlchemy
Path processing with takewhile and dropwhile
Basic authentication and Digest authentication with Flask
Introduction to RDB with sqlalchemy II
Hadoop introduction and MapReduce with Python
[GUI with Python] PyQt5-Drag and drop-
Compare DCGAN and pix2pix with keras
Reading and writing NetCDF with Python
Save and retrieve files with Pepper
Async / await with Kivy and tkinter
I played with PyQt5 and Python3
Experimented with unicode, decode and encode