I hvve some eror , when I m trying to write this query with having clause its give me error of sqlstate column not found
$collection = Mage::getResourceModel('sales/order_collection')
->addAttributeToSelect('*')
->joinAttribute('billing_firstname', 'order_address/firstname', 'billing_address_id', null, 'left')
->joinAttribute('billing_lastname', 'order_address/lastname', 'billing_address_id', null, 'left')
->joinAttribute('shipping_firstname', 'order_address/firstname', 'shipping_address_id', null, 'left')
->joinAttribute('shipping_lastname', 'order_address/lastname', 'shipping_address_id', null, 'left')
->addExpressionAttributeToSelect('billing_name',
'CONCAT({{billing_firstname}}, " ", {{billing_lastname}})',
array('billing_firstname', 'billing_lastname'))
->addExpressionAttributeToSelect('shipping_name',
'CONCAT({{shipping_firstname}}, " ", {{shipping_lastname}})',
array('shipping_firstname', 'shipping_lastname'))
->joinAttribute('shipping_country_id', 'order_address/country_id', 'shipping_address_id', null, 'left')
->addExpressionAttributeToSelect('international',
'("US" = {{shipping_country_id}})',
array('shipping_country_id'))
->joinField('item_product_id', 'sales/order_item', 'product_id', 'order_id=entity_id', null, 'left')
->groupByAttribute('entity_id');
// Add the presale column
$collection->getSelect()->joinLeft(
array('product_presale'=>'catalog_product_entity_int'),
'product_presale.entity_id=`_table_item_product_id`.`product_id` and product_presale.attribute_id='.$productattribute->getAttributeId(),
array('presale_item_count'=>new Zend_Db_Expr('SUM(product_presale.value)'))
);
but when I dump that query and run on phpmyadmin it works fine
Any help
Sajid