[Dbix-class] How to realize query with GROUP BY, LEFT JOIN, AND COUNT?

Matt S Trout dbix-class at trout.me.uk
Thu Aug 9 15:07:49 GMT 2007


On Thu, Aug 09, 2007 at 04:20:27PM +0400, dreel wrote:
> I need to realize this query in DBIx - but it's no things in newbie head how to do it...

Define the JOIN as a relationship, I guess a has_many from Network to Node.

use +select and +as to get the count

Read the ResultSet POD for docs on those and the join and group_by attrs

> SELECT net_name, COUNT(node_id) as dev_count
> FROM [dbo].[networks] nw
> LEFT JOIN nodes nd ON nw.net_id = nd.net_id
> GROUP BY net_name
> 
> result:
> net_name   dev_count
> --------   ----------
> net1        7
> 
> 
> ----
> dr.eel
> 
> _______________________________________________
> List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.rawmode.org

-- 
      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director    Want a managed development or deployment platform?
 Shadowcat Systems Ltd.  Contact mst (at) shadowcatsystems.co.uk for a quote
http://chainsawblues.vox.com/                    http://www.shadowcat.co.uk/ 



More information about the DBIx-Class mailing list