0
我试图让从我的销售表吐出这样的查询:Laravel雄辩:多选和where子句查询
For each `Brand`
`Brand` {
this month `sum(quantity)`
this month last year `sum(quantity)`
this year `sum(quantity)`
this last year `sum(quantity)`
`Brand` name
}
Next `Brand` {
this month `sum(quantity)`
this month last year `sum(quantity)`
this year `sum(quantity)`
this last year `sum(quantity)`
`Brand` name
}
我有这个,但它不是吐出任何东西。如果我删除wheres它会得到这些款项不在我需要的日期范围内,所以我知道它的问题。我不确定是否可以做多个小麦
public function sales()
{
return $this->hasMany('App\Sale', 'account_vip_id', 'vip_id')
->select('brand', DB::raw('sum(quantity) as month'))->whereMonth('date','=',date('m'))
->addSelect('brand', DB::raw('sum(quantity) as month_last'))->whereDate('date','=',date('m Y',strtotime("-1 year")))
->addSelect('brand', DB::raw('sum(quantity) as year'))->whereYear('date','=',date('Y'))
->addSelect('brand', DB::raw('sum(quantity) as year_last'))->whereYear('date','=', date("Y",strtotime("-1 year")))
->groupBy('brand');
}
select必须像' - > select([])''。选择列表必须在列 – Faradox
如果我删除了'where'选项并且addSelect工作正常 – Packy
在“选择”之后移动所有的列表。 – Faradox