On Apr 10, 2008, at 5:11 PM, Lukasz Szybalski wrote:

>
> Hello,
> I am trying to do a simple query which gets id, count(*)  group by id,
>
> s
> =
> sqlalchemy
> .select
> ([th
> .RECORD_NO
> ,sqlalchemy
> .func
> .count
> (th
> .RECORD_NO
> )],sqlalchemy
> .and_
> (th
> .APPLIED_TEST
> ==1,th.CODING_DATE=='20080404')).group_by(th.RECORD_NO).execute()
>
> This produces:
> SELECT [xxxx].[RECORD_NO], count([xxxx].[RECORD_NO]) AS count_1
> FROM [xxxx]
> WHERE [xxxx].[APPLIED_TEST] = ? AND [xxxx].[CODING_DATE] = ? GROUP BY
> [xxxx].[RECORD_NO]
>
> is there a way to replace this the 'count(*) as count_1' to whatever
> name I pick? count(*) as MY_GREAT_COUNT   ??!?

count('*').label('somename')

> Also what would be a syntax to make a same selection using  
> session.query(th)?

what would you like the ORM query to return ?  Object instances ?   
currently, using group_by() and such with Query implies you're getting  
individual column tuples back using _values(), in which case its  
sess.query(THsClass).group_by(whatever)._values(<col expressions>).

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
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