mysql - Every derived table must have its own alias Error? -
why following sub routine throws every derived table must have own alias error?
sub ok_wait { $str= shift; $dbh = &connect or die "cannot connect sql server \n"; $dbh->do("use $str;"); $stmt="select name,jobs_ok,jobs_wait (select name,jobs_ok,jobs_wait files order name limit 5) t union select 'others',sum(jobs_wait)as jobs_wait,sum(jobs_ok)as jobs_ok from(select jobs_wait,jobs_ok files order name limit -1 offset 5) t;"; $sth = $dbh->prepare( $stmt ); $sth->execute() or die $sth->errstr; $tmp = 0; while(my @row_array=$sth->fetchrow_array) { if ($tmp == 0) { $var_ok .= "\[\"$row_array[0] \($row_array[2]\)\",$row_array[2]\]"; $var_wait .= "\[\"$row_array[0] \($row_array[1]\)\",$row_array[1]\]"; $tmp++; } $sth->finish; $dbh->disconnect(); }
changed limit value
"select name,jobs_ok,jobs_wait ((select name,jobs_ok,jobs_wait files order name limit 5) union (select 'others',sum(jobs_wait)as jobs_wait,sum(jobs_ok) jobs_ok (select jobs_wait,jobs_ok files order name limit 0 offset 5) foo)) foo ";
note: not tested typed here directly, need put alias sub queries.
Comments
Post a Comment