Created
November 4, 2013 14:29
-
-
Save mmautner/7303273 to your computer and use it in GitHub Desktop.
example sqlalchemy ORM query
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# get count of users by birthday who've clicked in the last 7 days | |
results = session.query(User)\ | |
.join(Click, User.id == Click.user_id)\ | |
.filter(Click.created_at > datetime.datetime.today() - datetime.timedelta(days=7))\ | |
.groupby(User.birthday)\ | |
.orderby(User.birthday)\ | |
.values(User.birthday, | |
func.count(func.distinct(User.id))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment