计算总和&从数据库表中分钟所有列

时间:2016-06-02 18:50:23

标签: php mysql

我正在使用此代码计算所有数字。我在所有表格中添加了价格/数字(10)

$SQL = "SELECT p1 + p2 + p3 + p4 - p0 as total_price from table WHERE id = '1'";

此查询对我有用,首先对所有表格求和p1 = 10 + p2 = 10 .....结果40减去p0 = 2总价格38。

但我想从所有列中减去p0,如

  

" p1 = 10" - " p0 = 2" = 8
  " p2 = 10" - " p0 = 2" = 8
  " p3 = 10" - " p0 = 2" = 8
  " p4 = 10" - " p0 = 2" = 8

     

和和p1 + p2 + p3 + p4最终结果= 32

1 个答案:

答案 0 :(得分:1)

你可以(p1 + p2 + p3 + p4) - 4 * p0。顺便说一句4 * 8 = 32