我正在开发php的销售点。我有两个不同的销售。我在第一次销售中销售了4部手机,并在第二次销售中销售了2部手机。以下查询在收据上打印了2件。但是我只想显示一件数量为6的物品(手机)?
<?php
$result = $db->query("SELECT * FROM stock_sales where date BETWEEN '$fromdate' AND '$todate' ");
while ($line = $db->fetchNextObject($result)) {
?>
<tr>
<td><?php echo $line->stock_name; ?><
<td><?php echo $line->quantity; ?></td>
</tr>}
答案 0 :(得分:0)
将您的查询修改为
SELECT stock_name, count(*), sum(quantity) AS sum_quantity FROM stock_sales where date BETWEEN '$fromdate' AND '$todate' group by stock_name