如何修复created_at?

时间:2019-08-31 04:32:51

标签: mysql laravel

错误:

SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'created_at' in where clause is ambiguous (SQL: select `title`, sum(city_population) as sum from `provinces` inner join `ground_province` on `provinces`.`id` = `ground_province`.`province_id` inner join `grounds` on `grounds`.`id` = `ground_province`.`ground_id` where year(`created_at`) = 2019 group by `title`)

代码:如何使用create_at修复此代码?有人帮我

 $current_year = Carbon::today();
    $year = $current_year->year;
    $grounds=DB::table('provinces')

->join('ground_province','provinces.id','ground_province.province_id')
        ->join('grounds','grounds.id','ground_province.ground_id')
        ->select('title',\DB::raw('sum(city_population) as sum'))->whereYear('created_at', $year)
        ->groupby('title')->get();

    $title=[];
    $ground=[];
    foreach ($grounds as $key => $value) {
        $title[$key]=$value->title;
        $ground[$key]=$value->sum;
    }

0 个答案:

没有答案