【发布时间】:2017-07-18 13:31:06
【问题描述】:
我想统计所有状态为“可见”和“幽灵”的用户,如下所示:
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`)
感谢您的帮助!
【问题讨论】:
-
你有这个状态的历史吗?当您只有用户的当前状态时,这是不可能的。
-
是的,我有,我的 whereIn 没问题
-
在这行
DB::raw('MONTH(date_signalement) month')你错过了一个月前as -
我修复了这个问题,但没有任何改变