2

有没有办法通过字段中包含的字符串的长度来排序这个查询Title

    $query = $this->getEntityManager()
        ->createQuery('
    SELECT b FROM AcmeTestBundle:Blog b
    WHERE b.Title LIKE :title'
    )->setParameter('title','%'.$title.'%');

ORDER BY b.Title.length()似乎不起作用。

4

1 回答 1

5

是的,只需尝试:

$query = $this->getEntityManager()->createQuery('SELECT LENGTH(b.Title) l, b FROM AcmeTestBundle:Blog b WHERE b.Title LIKE :title ORDER BY l')->setParameter('title','%'.$title.'%');
于 2012-08-26T12:46:31.900 回答