Hi !
I am pretty new to elixir..
How to execute group by query ?
Any more elixir-like solution than pure SQLAlchemy used in example
[1]:
session.query(func.count(Movie.year),Movie.year).group_by
(Movie.year).all()
?
TIA !
[1]
from sqlalchemy import func
from elixir import *
metadata.bind = "sqlite:///movies.sqlite"
metadata.bind.echo = True
class Movie(Entity):
title = Field(Unicode(30))
year = Field(Integer)
description = Field(UnicodeText)
def __repr__(self):
return '<Movie "%s" (%d)>' % (self.title, self.year)
setup_all()
create_all()
Movie(title=u"Blade Runner", year=1982)
Movie(title=u"Blade Runner again", year=1982)
Movie(title=u"Some Recent Crap", year=2009)
session.commit()
print "movies: %r" % (Movie.query.all(),)
# http://www.sqlalchemy.org/docs/05/ormtutorial.html?highlight=filter
# session.query(func.count(User.name), User.name).group_by
(User.name).all()
# print "movies per year: %r" % (Movie.query(func.count
(Movie.year),Movie.year).group_by(Movie.year).all(), )
print "movies per year: %r" % (session.query(func.count
(Movie.year),Movie.year).group_by(Movie.year).all(), )
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"SQLElixir" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sqlelixir?hl=en
-~----------~----~----~----~------~----~------~--~---