Oleg Broytmann wrote: > On Tue, Oct 17, 2006 at 06:26:53PM +0200, Olivier Ravard wrote: > >> I use SQLObject for my project and I want to use a GROUP BY query. >> But the folowing line does not work : >> >> Item.select(groupBy='name') >> > > Think for a minute about the underlying SQL. > Item.select() > runs the query > SELECT * FROM item > and fills the list of object returning by the call with values of > attributes from the table, according to the description of columns you have > gave in the Item class: > > class Item(SQLObject): > name = StringCol() > > Right? Well, now think about > Item.select(groupBy='name') > It should generate the query > SELECT COUNT(*) FROM item GROUP BY name. > Oops. Where from should come that COUNT()? May be you want AVG()? Or > MAX()? > Where to put the resulting values? The Item class doesn't have any > description for it. > > >> How can I make a GROUP BY query ? >> > > using lower-level module SQLBuilder: > > from sqlobject.sqlbuilder import Select > select = Select([Item.q.name], groupBy="name") > results = connection.query(connection.sqlrepr(select)) > Thanks. It was what I am searching... But when I run this part of code, it returns None ! > Oleg. >
------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ sqlobject-discuss mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
