减去2列并回显仅高于零的行

时间:2013-08-27 01:45:35

标签: php mysql

主题说我有问题。 假设我有3列的表。

materials | total amount | amount
==================================
mouse     | 5            | 2
keyboard  | 10           | 5
phone     | 5            | 5 

我用这段代码显示这个表。

$result = mysqli_query($con,"SELECT * FROM materials");
while($row = mysqli_fetch_array($result))
  {
  echo  $row['materials'] 
  echo  $row['total_amount']
}

现在我要像这样展示这张表。

materials | total amount 
========================
mouse     | 3           
keyboard  | 5

如何存档请指导我。

2 个答案:

答案 0 :(得分:3)

amount

中减去total amount
SELECT *
FROM tableName
WHERE `total amount` - amount > 0

答案 1 :(得分:2)

"SELECT `materials`,(`total_amount` - `amount`) AS `newAmount` FROM `materials` WHERE (`total_amount` - `amount`) > 0;"