[Dbix-class] Create and execute query
Maurice Height
mauriceh at bigpond.net.au
Tue Feb 7 13:54:57 CET 2006
Hi
I am attempting to learn DBIx::Class (version 0.05001) via some simple test
data in a MySQL database.
My setup is MySQL (v5.0.18) on WinXP, Activestate Perl (v 5.8.7 build 815).
I have a db table 'history' setup as:
-------------------------------
package DB_Schema::History;
use base qw/DBIx::Class/;
__PACKAGE__->load_components(qw/Core/);
__PACKAGE__->table('history');
__PACKAGE__->add_columns(qw/code day open high low close volume/);
__PACKAGE__->set_primary_key(qw/code day/);
1;
-------------------------------
I have got some very simple queries to work OK on this table
but I would like to do something more complicated like:
SELECT code, MIN(volume*low) AS min_traded, AVG(volume*low) AS av_traded,
AVG(close) AS av_close, AVG(volume) AS av_volume
FROM history
WHERE day >= '2006-02-01' AND day <= '2006-02-07' AND low >= 1.00
AND volume > 100000
GROUP BY code
How do I write a search command for the SQL above?
my $schema = DB_Schema->connect( $dsn, $user, $pwd, $attrs );
my $rs = $schema->resultset('History')->search({
select = ????
);
Maurice
More information about the Dbix-class
mailing list