Symfony Doctrine2使用orderby选择distinct(大小写时)

Symfony Doctrine2使用orderby选择distinct(大小写时),symfony,doctrine-orm,Symfony,Doctrine Orm,我在理论上有点困难。我想在一周中的某一天预订一个查询 我的意思是: 如果给定日期的日期为星期二,我希望在星期二、星期三、…、星期日、星期一之前订购 但是一场演出可以有好几天 我在这里得到的代码对order by起到了作用 public function getValidPerformancesByDay2($date, $max = 25, $from, $asSql = false){ $myday = intVal(date('w',strtotime($date)));

我在理论上有点困难。我想在一周中的某一天预订一个查询

我的意思是:

如果给定日期的日期为
星期二
,我希望在
星期二、星期三、…、星期日、星期一
之前订购

但是一场演出可以有好几天

我在这里得到的代码对order by起到了作用

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();
}
公共函数getValidPerformancesByDay2($date,$max=25,$from,$asSql=false){
$myday=intVal(日期('w',strottime($date));
$q=$this->getEntityManager()
->createQueryBuilder()
->选择('DISTINCT textdesc,
当(perfdays.id<'.$myday')然后perfdays.id+8时的情况
ELSE perfdays.id以隐藏的sortvalue'结尾)
->from('sys4winsegundaBundle:Performance','textdesc')
->加入('textdesc.days','perfdays')
->其中('textdesc.enddate>=:date')
->andWhere('textdesc.isvalid=true')
->orderBy('sortvalue','ASC')
->setMaxResults($max)
->setFirstResult($from)
->setParameter('date',$date)
;
$query=$q->getQuery();
如果($asSql){
返回$query;
}
返回$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 
选择不同的p0.id作为id0,p0.name作为name1,p0.duration作为duration2,
p0_u.added by AS added by 3,p0_u.startdate AS startdate 4,p0_uu.enddate AS enddate5,
p0。starthour作为starthour 6,p0。flyer作为flyer 7,p0。price作为price 8,
p0.折扣为折扣9,p0.有效为有效10,
p0.存档为存档11,p0.描述为描述12,
p0..weblink为weblink13,p0..techinfo为techinfo14,p0..slug为slug15,
当(d1_.id<4)然后d1_.id+8,否则d1_.id终止为sclr16,
p0.place_id为place_id17,p0.gallery_id为gallery_id18
p0\内部连接性能\第p2天p2\在p0\ id=p2\性能\ id上
内部联接日d1_uu在d1_u.id=p2_u.day_uid,其中p0_uu.enddate>=?及
p0.isvalid=1个sclr16 ASC偏移量为0的订单
参数:['2012-08-23']
时间:5.13毫秒
也就是说,如果一次表演一周发生3次,我会得到3次

有人有主意吗


编辑 我的英语很差,我会尝试用不同的方式来解释: 我在不同的日子里都有艺术表演

我想做的是按最接近的时间顺序订购。 但我将其发送到数据库的方式是开始日期、结束日期,然后是发生的日期(星期二、星期三…)


我的查询会这样做(按最近的一个排序),但由于某些性能发生了,例如在星期三和星期五,我的查询将返回该性能2次(星期三为on,星期五为另一个),而我应该只在每次性能发生时检索,但顺序相同(最近的第一个)

如果您希望每周出现一次,请使用

$q->groupBy()
用于转换为周数的日期。并在选择中使用count()。我不确定我是否理解你的问题