Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: DBIx::Class Query Help

by anonymized user 468275 (Curate)
on Apr 26, 2011 at 14:42 UTC ( [id://901363]=note: print w/replies, xml ) Need Help??


in reply to DBIx::Class Query Help

You can reduce this to a single query by filtering the groups returned by GROUP BY with a HAVING clause, i.e.
SELECT project_id, chart_id, SUM(amount) FROM ($sql) self GROUP BY project_id, chart_id HAVING SUM(amount) != 0

One world, one people

Replies are listed 'Best First'.
Re^2: DBIx::Class Query Help
by duelafn (Parson) on Apr 26, 2011 at 15:20 UTC

    Ah, fabulous that does help a lot. Aside from having to remove duplicates in perl, the following does exactly what I was after:

    sub accounts { my $self = shift; my $rs = $self->search({}, { select => ["project_id", "chart.accno", "chart.descript +ion", "SUM(amount)"], as => ["project_id", "accno", "description", "bal"] +, group_by => ["project_id", "chart.accno", "chart.descript +ion"], having => { 'SUM(amount)' => { '!=', 0 } }, join => [ "chart" ], }); $rs->result_class('DBIx::Class::ResultClass::HashRefInflator'); unique map "$$_{accno} - $$_{description}", $rs->all; }

    Good Day,
        Dean

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://901363]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-25 05:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found