2

我正在使用下面的代码对我的库存进行分组和汇总。对于我的一些库存,如果发货量多于库存量,我可能会得到负面结果,但我希望这些负数商品不要显示在我的“库存页面”中。有没有办法删除数量等于或小于 0 的行?

-------------------------------------------------------------------
ProductID   |  Color  | Timestamp          |  Quantity  |  RowID  |
-------------------------------------------------------------------
25          |  Red    | 10/10/10 06:22:15  |  -250      |  1      |
-------------------------------------------------------------------
32          |  Green  | 10/10/10 06:23:45  |  100       |  2      |
-------------------------------------------------------------------

$query = "SELECT productid, color, SUM(Quantity) AS TotalQuantity FROM inventory GROUP BY productid, color";
$result = mysql_query($query) or die(mysql_error());

   // Table markup here
   echo '<tr><td>'. $row['productid'] . '</td><td>' . $row['color']. '</td><td>'. $row['TotalQuantity'];
   // Table markup here
4

1 回答 1

3
$query = "Select * from 
  (SELECT productid, color, 
   SUM(Quantity) AS TotalQuantity FROM inventory 
   GROUP BY productid, color) AS alias 
where TotalQuantity  > 0";
于 2012-06-20T21:25:14.560 回答