我尝试在where->in
中的标识符中使用表达式。
例如SQL:
SELECT * FROM table WHERE DATE(created) IN ('2014-03-05','2013-06-07')
我尝试过使用它:
$days = ['2014-03-05','2013-06-07'];
$where = new Where();
$where->addPredicate(new Predicate\In(new Expression('DATE(created)'), $days));
$select->where($where);
它不起作用
答案 0 :(得分:1)
仍然无法通过Predicate\In
找到解决方案但找到了可以用来运行的解决方案 -
$days = array('2014-08-07', '2014-08-08');
$platform = $this->tableGateway->adapter->getPlatform();
$predicateIn = 'DATE('.$platform->quoteIdentifierChain(array('created')).')';
$predicateIn .= " in (";
$predicateIn .= $platform->quoteValueList($days);
$predicateIn .= ")";
$select->where(array($predicateIn));
形成的SQL查询是 -
SELECT * FROM tablename WHERE DATE(created) in ('2014-08-07', '2014-08-08')
如果能找到所需的解决方案,肯定会告诉您。