此代码无效,因为它应该工作我想在开始和结束时段之间使用between和子句检查period_id但是无法做到如何
$return = Yii::app()->db->createCommand()
->select('period_id')
->from('SCHOOL_PERIODS')
->where('school_id=:school_id', array(':school_id'=>$schoolId))
->andWhere('syear=:syear', array(':syear'=>$schoolYear))
->andWhere('ignore_scheduling IS NULL')
->andWhere('period_id>:start', array(':start' => $startPeriod))
->andWhere('period_id<:end', array(':end' => $maxPeriod))
->order('sort_order asc')
->queryAll();
return $return;
答案 0 :(得分:2)
尝试在角括号之前和之后放置一个空格,如此
period_id > :start
如果仍然无效,请删除两行
->andWhere('period_id>:start', array(':start' => $startPeriod))
->andWhere('period_id<:end', array(':end' => $maxPeriod))
然后使用以下代码
->andWhere('period_id > :start AND period_id < :end', array(':start' => $startPeriod',':end' => $maxPeriod))
如果您想使用HAVING,请在分组下方添加此行。这意味着您可以使用已经运行的另一个查询来使用值。
->having('period_id > :resultfromOtherQueryStart AND period_id:resultFromOtherQueryEnd',array(':resultFromOtherQuery'=>$otherQueryStart,':otherQueryEnd'=>$otherQueryEnd))