我有一个产品存档列表,我正在使用 dotrine 和 symfony,我希望显示存档产品列表:
$query = Doctrine::getTable('Product')
->createQuery('a')
->select('a.created_at, YEAR(a.created_at) as year, MONTH(a.created_at) as month')
->groupBy('year, month')
->orderBy('a.created_at DESC')
->setHydrationMode(Doctrine_Core::HYDRATE_ARRAY)
->execute();
所以我希望改变查询,所以当超过 1 年时它应该按年对添加的产品进行分组?
编辑:
我添加了这个,但我想它不适用于学说 1:
->andWhere("year <= DATE_ADD(CURRENT_DATE(), 1, 'YEAR')")
我收到此错误:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1, 'YEAR')