文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>sqlalchemy group by

sqlalchemy group by

时间:2010-10-11  来源:lexus


Re: [sqlalchemy] Simple example of a GROUP BY

Lance Edgar
Mon, 05 Jul 2010 21:24:08 -0700

On 7/5/2010 10:55 PM, Andrew Bialecki wrote:
I've looked for a while, but I can't find the *best* way to use the
ORM to generate the following query:

SELECT user_id, count(*) cnt
FROM orders
GROUP BY user_id

I have classes that represent both User and Order.  So what should go
after:

Order.query.[fill this in]

Sorry this is such an easy question, feel free to forward me to an
example, I just couldn't find one.
I think the following might work?


from sqlalchemy import func

session.query(Order.user_id, func.count(Order.user_id)).group_by(Order.user_id)
Anyway a little more is to be found here:

http://www.sqlalchemy.org/docs/ormtutorial.html#counting
http://www.sqlalchemy.org/docs/reference/orm/query.html#sqlalchemy.orm.query.Query.group_by

Lance

--
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
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载