Get the maximum and minimum averages from the database in Perl
Let's get the maximum and minimum averages from the database in Perl. I'm using Perl's DBI module to get the SQL-created stats for the MariaDB database.
use strict; use warnings; use DBI; my $dbh = DBI->connect( "DBI:mysql:kimotosystem:localhost", "kimoto", "kimoto" ) or die "cannot connect to MySQL: $DBI::errstr"; my $sth = $dbh->prepare("SELECT min(price), max(price), avg(price) FROM kimotosystem.book;"); $sth->execute(); my $hash_ref = $sth->fetchrow_hashref; print "min=$hash_ref->{'min(price)'}, max=$hash_ref->{'max(price)'}, avg=$hash_ref->{'avg(price)'}\n"; $sth->finish; $dbh->disconnect;