I have the following queries which calculates the total order sale happened in last 5 months,
> SELECT SUM(o.total), DATE(o.order_date) dateonly FROM `order` as o where (o.order_date BETWEEN last_day(NOW() - INTERVAL 5 MONTH) AND
> date_format(NOW(), '%Y-%m-%d') AND (o.order_status = "P" OR
> o.order_status = "T" OR o.order_status = "S" OR o.order_status = "D"
> )) GROUP BY month(o.order_date)
I am trying to implement above query in zend. But I stuck on middle. I have the code taken from models/DbTable,
class Default_Model_DbTable_Order extends Zend_Db_Table_Abstract
{
protected $_name = 'order';
protected $_primary = 'order_id';
public function month_based_orderlist()
{
$oDb = Zend_Registry::get("db");
$whereSQL = 'o.order_id > 0';
$whereSQL .= ' AND o.status = 1';
$whereSQL .= ' AND o.order_date BETWEEN last_day(NOW() - INTERVAL 5 MONTH) AND date_format(NOW(),'.%Y-%m-%d.')';
$whereSQL .= ' AND o.order_status = "P"';
$whereSQL .= ' OR o.order_status = "T"';
$whereSQL .= ' OR o.order_status = "S"';
$whereSQL .= ' OR o.order_status = "D"';
$select = $oDb->select()
->from(
array('o' => $this->_name),
array(
'lifetimesale' => new Zend_Db_Expr('SUM(o.total)'),
'dateonly' => DATE('o.order_date')
)
)->where($whereSQL);
//echo $select; exit;
$result = $this->getAdapter()->fetchAll($select);
// print_obj($result);
return $result;
}
}
?>
I am trying to implement the sql query like above,what i done wrong on this. Kindly help me on this