【发布时间】:2018-02-04 14:35:30
【问题描述】:
我执行了六次查询以返回多个结果集。所有呼叫的查询都相同,但参数仅有所不同。如下:
public function getGroupedInfo($id, $type, $zip, $field) {
return DB::table('data')
->select(DB::raw("{$field} as obj, COUNT(*) as count"))
->where('report_id', $id)
->where('book_section', $type)
->where('zip_code', $zip)
->groupBy("{$field}")
->orderBy('count', 'DESC')->get();
}
我调用函数如下:
public function stats(Request $request){
$schools['Elementary Schools'] = $this->getGroupedInfo($id, $listing_type, $zip_code, 'elementary_school');
$schools['Middle Schools'] = $this->getGroupedInfo($id, $listing_type, $zip_code, 'middle_school');
$schools['High Schools'] = $this->getGroupedInfo($id, $listing_type, $zip_code, 'high_school');
$others['lot_sqft'] = $this->getGroupedInfo($id, $listing_type, $zip_code, 'lot_sqft');
}
我打算将它们添加到单个存储过程中,但我不确定如何在单个存储过程中编写它们,然后在 Laravel 端使用结果。
你能帮我解决这个问题吗?提前致谢。
【问题讨论】:
标签: php mysql stored-procedures laravel-5