SQL查询(Zend框架)

时间:2015-07-15 21:55:45

标签: php mysql optimization

如果另一列为1或2

,如何从同一列中减去
->from('product', array('SUM(weight)')
->where('store = 1')

如果存储设置为2,则应始终减去重量值。

1 个答案:

答案 0 :(得分:1)

如果可以,请继续尝试...

$selectCounting = $productsTable->select();
$selectCounting ->from('product', 
                       array('SUM(IF(store = 2, 0, weight)) AS `totalweight`', 
                      'product', 
                      'weight'))
                ->where ('1=1')

enter image description here