In ZEND
$select = $db->select()
->from('points',array(new Zend_Db_Expr('sum(value)')))
->where('userId = ?', $userIdDB);
當添加表達列
列在SQL查詢有時表情,從表中不是簡單地列 名。表達式不應具有相關名稱或 適用的引用。如果您的列字符串包含圓括號,則 Zend_Db_Select將其識別爲表達式。
您還可以顯式創建Zend_Db_Expr類型的對象,以 防止將字符串視爲列名稱。 Zend_Db_Expr是 一個包含單個字符串的最小類。 Zend_Db_Select 可識別類型爲Zend_Db_Expr的對象,並將它們轉換回 字符串,但不會應用任何更改(如引用或 相關名稱)。
EXAMPLE IN ZEND
// Build this query using Zend_Db_Expr explicitly:
// SELECT p."product_id", p.cost * 1.08 AS cost_plus_tax
// FROM "products" AS p
$select = $db->select()
->from(array('p' => 'products'),
array('product_id',
'cost_plus_tax' =>
new Zend_Db_Expr('p.cost * 1.08'))
);
,將返回總和(值),或表的一個int值? – o0skar
我現在修好了,試試吧 – underscore
能工作嗎? – underscore