我正在使用where条件进行简单的查询请求。我需要在这种情况下有一个日期字段的年份,在SQL中我使用"year (date)=2015"在laravel,当我使用它,我得到一个错误,因为他没有找到列。
$total_num_rows_y = DB::table('insatisfaction')
->select(DB::raw('COUNT(id) as total_num_rows_y'))
->where('foo', $foo->id_aj)
->where('YEAR(date)', '2015')
->get();
你能帮我吗?
我们试试:
$total_num_rows_y = DB::table('insatisfaction')
->select(DB::raw('COUNT(id) as total_num_rows_y'))
->where('foo', $foo->id_aj)
->where(DB::raw('YEAR(start)'), '=', date('Y'));
->get();
可以使用whereYear
$total_num_rows_y = DB::table('insatisfaction')
->select(DB::raw('COUNT(id) as total_num_rows_y'))
->where('foo', $foo->id_aj)
->whereYear('date','=',2015)
->get();