这是我的sql:
SELECT id,`status`,IF(`status` = 'active', 'deleted','active') AS `status-use`
FROM categories
这是我的代码:( ActionResourceModel
是Zend_Db_Table
)
$dbTable = $this->getActionResourceModel();
$select = $dbTable->select();
$select->from($dbTable,$this->getQueryColumns());
$select->order($orderClause.' '.$orderSpec);
如何添加到我的选择对象:
IF(`status` = 'active', 'deleted','active') AS `status-use`
答案 0 :(得分:0)
您的选择应如下所示:
$dbTable = $this->getActionResourceModel();
$select = $dbTable->select();
$select->from(
$dbTable,
array(
'status-use' => new Zend_Db_Expr("IF(`status` = 'active', 'deleted','active')"
)
);
答案 1 :(得分:-1)
您可以从Zend_Db_Table
扩展并定义创建此查询的函数。你可以看到Zend_Db_Table
函数,如join
,from
等,以设计你的特殊类