我想把状态为“可见”和“鬼”的所有用户数如下:
public function getStatsUser() {
$data = self::whereIn('state', array('Visible', 'Ghost'))
->count();
return $data;
}但是,我希望每个月都能从第一个用户那里获得这些数据,如下所示:
['Month', 'Data'],
['December 2016', 4000],
['January 2017', 4600],
['February 2017', 11020],
['March 2017', 5400]对于日期,我有一个"created_at“行,而不是一个月的特定行。
我试过了,但不起作用
$data= self::select(DB::raw('count(*) as monthly_total'), DB::raw('MONTH(created_at) as month'))
->whereIn('state', array('visible', 'Ghost'))
->whereYear('created_at', '=', date('Y'))
->groupBy('month')
->count();错误:
SQLSTATE[42S22]: Column not found: 1054 Champ 'month' inconnu dans group statement (SQL: select count(*) as aggregate from `oiseau` where `etat_actuel` in (Relaché, En convalescence) and year(`date_signalement`) = 2017 group by `month`)谢谢你的帮助!
发布于 2017-07-17 13:28:29
你可以试着:
$data = self::whereIn('state', array('Visible', 'Ghost'))
->select(DB::raw('count(*) as monthly_total') , DB::raw('MONTH(created_at) month'))
->groupBy('month ')
->get();如果月份存储在其他表中,则尝试联接查询。
https://stackoverflow.com/questions/45145218
复制相似问题