我对 postgres 数据库有多个查询,我希望将数据返回到该数据库。当前在两列中的几行上返回数据,这是错误的。我希望数据显示在一行和几列中。查询是这样的:
<?php
$sql = "Select ceil(SUM (a.CALLDURATION::integer) / 60) AS minutes, sum(a.alltaxcost::integer) AS revenue
FROM cdr_data a,COUNTRY_CODES b
WHERE a.CALLSUBCLASS = '002'
AND a.CALLCLASS = '008'
and a.zoneiddest::integer > 0
AND SUBSTR (a.CALLEDNUMBER, 1, 2) NOT IN
('77', '78', '75', '70', '71', '41', '31', '39', '76','79')
and not substr(a.zoneiddest,1,3) in ('254','255','211','257','250','256')
and trim(a.zoneiddest) = trim(b.country_code)
union
select ceil(sum(callduration::integer/60) )as total_minutes,round(sum(alltaxcost::integer) ,2)as revenue
from cdr_data
where callclass ='008' and callsubclass='001'
and callduration::integer >0
and regexp_replace(callednumber,'^256','') ~ '^73'
and bundleunits = 'Money'
and regexp_replace(callednumber,'^256','') ~ '^73'
union
select ceil(sum(callduration::integer/60) )as total_minutes,round(sum(alltaxcost::integer) ,2)as revenue
from cdr_data
where callclass ='008' and callsubclass='001'
and callduration::integer >0
and identifiant ~'^73'
and bundleunits = 'Money'
and zoneorange <> '-1'
union
SELECT sum(a.alltaxcost::integer) AS revenue, ceil(SUM (a.CALLDURATION::integer) / 60) AS minutes
FROM cdr_data a, COUNTRY_CODES b
WHERE a.CALLSUBCLASS = '002'
AND a.CALLCLASS = '008'
and a.zoneiddest::integer > 0
AND SUBSTR (a.CALLEDNUMBER, 1, 2) NOT IN
('77', '78', '75', '70', '71', '41', '31', '39', '76','79')
and substr(a.zoneiddest,1,3) in ('254','255','211','257','250')
and trim(a.zoneiddest) = trim(b.country_code)
";
$result = pg_query($dbh, $sql);
if (!$result) {
die("Error in SQL query: " . pg_last_error());
}
while ($row = pg_fetch_array($result)) {
echo "<tr style='background-color: #FFFFFF;font-size:15px' align='center'>";
echo "<td>" . $row[0] . "</td>";
echo "<td>" . $row[1] . "</td>";
echo "<td>" . $row[2] . "</td>";
echo "<td>" . $row[3] . "</td>";
echo "<td>" . $row[4] . "</td>";
echo "<td>" . $row[5] . "</td>";
echo "<td>" . $row[6] . "</td>";
echo "<td>" . $row[7] . "</td>";
echo "<td>" . $row[8] . "</td>";
echo "<td>" . $row[9] . "</td>";
echo "<td>" . $row[10] . "</td>";
echo "<td>" . $row[11] . "</td>";
echo "</tr>";
}
// free memory
pg_free_result($result);
// close connection
pg_close($dbh);
?>
这将我的数据显示为:
International Minutes International Revenue Onnet Minutes Onnet Revenue
0 0
1343 578086
这不是我想要的。我希望结果是这样的
International Minutes International Revenue Onnet Minutes Onnet Revenue
0 0 1343 578086
所以我希望我的结果在一行和超过 10 列中返回。我怎样才能做到这一点。