use strict; use lib '.'; use Clauses; #use SQL::Abstract::Clauses; my $s = SQL::Abstract::Clauses->new(); my $where = { 1 => 0 }; # some preexisting where clause my $total_count = 13; for my $column (qw(artist album)) { my ($sql,@bind) = $s->select('foo',[ $column, 'count(*) as col_count' ], where => $where, order_by => [ "$column asc", 'col_count desc' ], having => { col_count => [ -and => { '>' => 0 }, { '<' => $total_count }]},); print $sql,"\n"; }