我有这张表:
表 addonlist_final
表插件
首先,我必须JOIN
相同addon_id
所以我可以获得所有必需的详细信息(我已经完成了)。然后,我想在JOIN
中column
table
<?php
include("conn.php");
echo "<table border='1' >";
echo "<tr>";
echo "<th>Description</th>";
echo "<th>Price</th>";
echo "<th>Qty</th>";
echo "<th>Total Cost</th>";
echo "</tr>";
$totaldue = 0;
$currentaddons = mysql_query("SELECT a.*, af.*
FROM addons AS a, addonlist_final AS af
WHERE a.addon_id = af.faddon_id and af.ftransac_id='2685'
ORDER BY af.timef DESC
");
while($rows = mysql_fetch_assoc($currentaddons)){
$desc = $rows['description'];
$price = $rows['price'];
$qty = $rows['quantity'];
$totalcost = $price * $qty;
$totaldue += $price * $qty;
echo "<tr>";
echo "<td>$desc</td>";
echo "<td>$price</td>";
echo "<td>$qty</td>";
echo "<td>$totalcost</td>";
echo "</tr>";
}
echo "</table>";
echo "<h3>Total Due: ".number_format($totaldue)."</h3>";
?>
具有相同身份(addon_id),然后将数量相互添加。
到目前为止,我有这段代码:
{{1}}
这告诉我这个:
我想表现的是:
只需一个查询就可以实现吗?在此先感谢:)
答案 0 :(得分:4)
您必须使用group by
SELECT a.description, sum(af.quantity) as quantity,price
FROM addons AS a, addonlist_final AS af
WHERE a.addon_id = af.faddon_id and af.ftransac_id='2685'
group by a.description
ORDER BY af.timef DESC