[CDBI] Group by and AbstractSearch

Bill Moseley moseley at hank.org
Fri Oct 21 15:48:00 BST 2005


On Fri, Oct 21, 2005 at 09:53:27AM -0400, Brett Sanger wrote:
> I'm trying to aggregate some data with a group by statement, and I want
> to use the AbstractSearch Plugin to allow me to optionally restrict it.
> 
> (Failing that, I want to use SQL::Abstract)
> 
> The Wiki gave me hints towards the following code:
> 
> (In my class)
> 
> __PACKAGE__->set_sql( summarize =>
>   "select fips, provider_type, count(id) as Count
>   from __TABLE__
>   %s
>   group by fips, provider_type"
> );
> 
> sub area_summary {
>   my $self = shift;
>   my $sql = SQL::Abstract->new();
>   my ($where, @bind) = $sql->where(@_);
>   return $self->sql_summarize($where)->select_val(@bind);
> }

Doesn't select_val() return just one value?  Seem like in the case
above you would define a TEMP column 'Count' and then search as
normal with $class->search_summarize()

-- 
Bill Moseley
moseley at hank.org





More information about the ClassDBI mailing list