统计我要统计所有谁都有状态的用户“看得见”和“幽灵”是这样的:Laravel 5.4 - 每月
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`)
感谢您的帮助!
你保持这种状态的历史?当你只有用户的当前状态时,不可能这样做。 – Jerodev
是啊,我有,我的其中是确定 – TuxxyDOS
在这一行'DB ::原料('MONTH(date_signalement)一个月)'你已经错过了'as'月 –