getTable('sales_order'); $tableOrderItem = $this->getTable('sales_flat_order_item'); $select = $installer->getConnection()->select() ->from($tableOrderItem, array( 'total_qty_ordered' => 'SUM(qty_ordered)', 'entity_id' => 'order_id')) ->group(array('order_id')); $installer->run('CREATE TEMPORARY TABLE `tmp_order_items` ' . $select->assemble()); $select->reset() ->join('tmp_order_items', 'tmp_order_items.entity_id = order.entity_id', array('total_qty_ordered', 'entity_id')); $sqlQuery = $select->crossUpdateFromSelect(array('order' => $tableOrder)); $installer->getConnection()->query($sqlQuery); $installer->run('DROP TEMPORARY TABLE `tmp_order_items`');