如何将重复记录记录为一个,QUANTITY将根据下图将总数记录为3
这是代码:
$id=$_GET['invoice'];
include('connect.php');
$result = $db->prepare("SELECT * FROM sales_order WHERE invoice= :userid");
$result->bindParam(':userid', $id);
$result->execute();
for ($i=0; $row = $result->fetch(); $i++) {
答案 0 :(得分:1)
您应该在查询中使用SUM()
和GROUP BY
。
SELECT SUM(Quantity), `Product Code`,
`Brand Name`, `Description Name`, `Price`, `Discount`, `VAT`, `Ammount`,
`Total Amount`
FROM sales_order WHERE invoice=:userid
GROUP BY `Product Code`, `Brand Name`, `Description Name`
您还可以执行以下操作:
SELECT *, SUM(Quantity)
FROM sales_order WHERE invoice=:userid
GROUP BY `Product Code`, `Brand Name`, `Description Name`