[Dbix-class] Count + having
Matt S Trout
mst at shadowcat.co.uk
Tue Jan 24 22:58:27 GMT 2017
On Tue, Jan 17, 2017 at 08:06:42AM +0000, RAPPAZ Francois wrote:
> But this
> $schema->resultset('Abo')->search_rs(
> {
> 'me.noabt' => $value_aref->[0],
> },
> { select => ['me.noabt', {count => 'abojrnabt.noabt', -as => 'count_abo'}],
> join => ['abojrnabt'],
> group_by => ['me.noabt'],
> having => \[ 'count(abojrnabt.noabt) > ?', 1 ] ,
> });
>
> works.
Unless I misremember, the SELECT list isn't necessarily in scope for HAVING.
Worth playing around at an SQL console to get a feel for how it actually
interacts; HAVING is awesome but something you tend to use rarely enough that
it's easy to forget how it works (I know I do, hence the 'unless' above ;)
--
Matt S Trout - Shadowcat Systems - Perl consulting with a commit bit and a clue
http://shadowcat.co.uk/blog/matt-s-trout/ http://twitter.com/shadowcat_mst/
Email me now on mst (at) shadowcat.co.uk and let's chat about how our CPAN
commercial support, training and consultancy packages could help your team.
More information about the DBIx-Class
mailing list