爲什麼我的後續子例程拋出每個派生表都必須有自己的別名錯誤?每個派生表都必須有它自己的別名Error?
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();
}
也許是因爲你有派生表沒有別名? – billynoah
上述更改顯示語法錯誤@ billynoah – SRVVANI
您的SQL語法中有錯誤;檢查與您的MySQL服務器版本相對應的手冊,選擇正確的語法以在'from(選擇jobs_wait,jobs_ok中的文件order by name limit -1')附近使用@billynoah – SRVVANI