它没有给我任何错误,但结果没有分组。
public function getNumberOfRetweetsOfMeByDate($fromDate, $toDate, $twId)
{
return $this->find()->asArray()
->select(["to_char (insert_time, 'YYYY-MM-DD') as time", "count(*) as number_of_retweets_of_me"])
->where("twitter_id = $twId")
->andWhere("insert_time >= '$fromDate'::DATE")
->andWhere("insert_time < '$toDate'::DATE +1")
->groupBy(['insert_time'])
->having('count(*) > 0')
->orderBy('insert_time')
->all();
}
答案 0 :(得分:1)
在groupBy和orderBy子句中使用别名time
而不是insert_time
。
$this->find()
->asArray()
->select(["TO_CHAR(insert_time, 'YYYY-MM-DD') as char_time", "COUNT(*) as number_of_retweets_of_me"])
->where("twitter_id = $twId")
->andWhere("insert_time >= '$fromDate'::DATE")
->andWhere("insert_time < '$toDate'::DATE +1")
->groupBy(['char_time'])
->having('COUNT(*) > 0')
->orderBy('char_time')
->all();
另一个提示:尝试避免使用mysql关键字作为字段名称或别名,这可能会在其他情况下导致问题。