On Jan 13, 2009, at 9:46 AM, Chen Houwu wrote:

>
> I am not very familiar with SqlAlchemy, now I have a problem to query
> with aggregate function.
>
> Here is the class
> --------------------------
> class Directory(DeclarativeBase):
>    """An ultra-simple group definition.
>    """
>    __tablename__ = 'docman_directory'
>    dir_id = Column(Integer, autoincrement=True, primary_key=True)
>    code = Column(Integer,default=1)
>    parent_id = Column(Integer, ForeignKey
> ('docman_directory.dir_id'))
> --------------------------
> I want to get the result of " select max(code) from docman_directory
> where parent_id='222' ",  what  clause should I use with DBSession?

session
.query
(func.max(Directory.code)).filter(Directory.parent_id=222).scalar()

or

session
.query
(Directory
).filter(Directory.parent_id=222).value(func.max(Directory.code))

hope this helps..



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" 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/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to