You can create a view for this query. e.g.
CREATE VIEW stats AS SELECT MIN(a), MAX(a), AVG(a) FROM table1;

On Mon, Sep 21, 2009 at 10:42 AM, Trevor Phillips <[email protected]
> wrote:

> I have a table of logged data, which is too granular to browse row by
> row. What I want to do is display a row per hour of data, and include
> average/min/max for each field.
>
> I can do this in SQL, using group by with a formatted timestamp field
> to group per hour, along with AVG(), MIN(), MAX() on each field to get
> the values I'm after. I can replicate the query in DBIx by defining
> 'select' and 'as'. However, I can't access these, I'm assuming because
> I've given them names which don't match my DBIx::Class' defined column
> names. A dump of the DBIx::Class shows the values in there as part of
> _column_data.
>
> So, for example, if my class has a column "foo", as does my DB table,
> then what I want to access is foo_avg, foo_min and foo_max.
>
> Is there an easy way to get a search resultset to auto-create the new
> columns?
> Is there a better way to accomplish what I'm after?
>
> I'm using DBIx::Class within Catalyst, with a MySQL DB, and Template
> Toolkit for presentation.
>
> Thanks.
>
> --
> Trevor Phillips  - http://dortamur.livejournal.com/
> "On nights such as this, evil deeds are done. And good deeds, of
> course. But mostly evil, on the whole."
>      -- (Terry Pratchett, Wyrd Sisters)
>
> _______________________________________________
> List: http://lists.scsys.co.uk/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/[email protected]
>
_______________________________________________
List: http://lists.scsys.co.uk/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/[email protected]

Reply via email to