为什么我的后续子例程抛出每个派生表必须有自己的别名错误?
sub ok_wait
{
my $str= shift;
$DBH = &connect or die "Cannot connect to the sql server \n";
$DBH->do("USE $str;");
my $stmt="select name,jobs_ok,jobs_wait from (select name,jobs_ok,jobs_wait from files order by name limit 5) t union all select 'others',sum(jobs_wait)as jobs_wait,sum(jobs_ok)as jobs_ok from(select jobs_wait,jobs_ok from files order by name limit -1 offset 5) t;";
my $sth = $DBH->prepare( $stmt );
$sth->execute() or die $sth->errstr;
my $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();
}
答案 0 :(得分:0)
更改了限制值
"select name,jobs_ok,jobs_wait from ((select name,jobs_ok,jobs_wait from files order by name limit 5) union all (select 'others',sum(jobs_wait)as jobs_wait,sum(jobs_ok) as jobs_ok from (select jobs_wait,jobs_ok from files order by name limit 0 offset 5) foo)) foo ";
注意:未经测试我只是直接在此处输入,但基本上您需要为子查询添加别名。