On Apr 11, 2008, at 12:51 PM, Lukasz Szybalski wrote:

>
> Is there a way to get this ?
> SELECT RECORD_NO, count(RECORD_NO) FROM table GROUP BY RECORD_NO
> (primary key is RECORD_ID)
>
> The only way I know how to do it is via sqlalchemy.select
> but I would like the query type of the return where my results are
> type(a) <type 'list'>
>>>> type(a[0])
> <class '__main__.th'>
>

If I understand correctly, you want the instances that correspond to  
those record_no records, and the count.  In this case:

s = select([th.RECORD_NO,  
func.count(th.RECORD_NO).label('count')]).group_by(th.RECORD_NO)

sess.query(th).select_from(th_table.join(s,  
th.RECORD_NO==s.c.RECORD_NO)).add_column(s.c.count).all()

for some insight into this approach, see 
http://weblogs.sqlteam.com/jeffs/archive/2005/12/14/8546.aspx 
  .

also again, the next release will have a more concise method of  
building that join as well.





--~--~---------~--~----~------------~-------~--~----~
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