運營商之間的SQL我有以下的疑問,它計算的總訂單銷售發生在過去的5個月,如何實現在Zend_Db的
> 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)
我想實現以上的Zend查詢。但我堅持中等。 我從模型/ 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;
}
}
?>
我想實現SQL查詢像上面,是我做錯了這一點。 請幫我在這
你需要更具體。你是怎麼被卡住的?你能發佈你收到的錯誤嗎?另外,如果你認爲這個問題必須處理zend,那麼也應該發佈該代碼。 –
你能解釋一下你說的是什麼問題嗎?你使用Zend_Db嗎? – Oleg
@Digital Precision現在更新我的問題。 – mymotherland