我在教义2上遇到了一些麻烦。我想订购查询,但要按星期几。
我是什么意思:
如果给定日期的日期在哪里Tuesday
,我希望它由Tuesday, Wednseday, ..., Sunday, Monday
.
但是一场演出可以有好几天。
我在这里得到的代码可以通过
public function getValidPerformancesByDay2($date, $max = 25, $from, $asSql = false){
$myday = intVal(date('w',strtotime($date)));
$q = $this->getEntityManager()
->createQueryBuilder()
->select('DISTINCT textdesc,
CASE WHEN (perfdays.id < '. $myday .') THEN perfdays.id + 8
ELSE perfdays.id END AS HIDDEN sortvalue')
->from ('sys4winsegundaBundle:Performance','textdesc')
->join('textdesc.days', 'perfdays')
->where ('textdesc.enddate >= :date')
->andWhere('textdesc.isvalid = true')
->orderBy('sortvalue','ASC')
->setMaxResults($max)
->setFirstResult($from)
->setParameter('date',$date)
;
$query = $q->getQuery();
if ($asSql){
return $query;
}
return $query->getResult();
}
但不幸的是,当我查看已发送的查询时,它是:
SELECT DISTINCT p0_.id AS id0, p0_.name AS name1, p0_.duration AS duration2,
p0_.addedby AS addedby3, p0_.startdate AS startdate4, p0_.enddate AS enddate5,
p0_.starthour AS starthour6, p0_.flyer AS flyer7, p0_.price AS price8,
p0_.discount AS discount9, p0_.isvalid AS isvalid10,
p0_.archivedon AS archivedon11, p0_.description AS description12,
p0_.weblink AS weblink13, p0_.techinfo AS techinfo14, p0_.slug AS slug15,
CASE WHEN (d1_.id < 4) THEN d1_.id + 8 ELSE d1_.id END AS sclr16,
p0_.place_id AS place_id17, p0_.gallery_id AS gallery_id18 FROM performances
p0_ INNER JOIN performance_day p2_ ON p0_.id = p2_.performance_id
INNER JOIN days d1_ ON d1_.id = p2_.day_id WHERE p0_.enddate >= ? AND
p0_.isvalid = 1 ORDER BY sclr16 ASC OFFSET 0
Parameters: ['2012-08-23']
Time: 5.13 ms
这意味着如果一个表演每周发生 3 次,我会得到 3 次。
有人知道吗?
编辑 我的英语很糟糕,我会尝试以不同的方式解释它:嗯,我有不同日子发生的艺术表演。
我想做的是按最近发生的时间对它们进行排序。但是我将它发送到数据库的方式是开始日期,结束日期,然后是它发生的日期(星期二,星期三......)
我的查询是这样做的(按最近的排序),但是由于例如在周三和周五发生了一些性能,我的查询将返回该性能 2 次(在周三,另一次在周五),而我应该只在每个发生时检索性能但顺序相同(最近的优先)