如何用laravel来实现以下sql呢?
select `book_name`, count(*) as num from `clock_books` group by `book_name`
可使用laravel的原始表达式DB::raw()来操作:
$books = DB::table('books')
->select('book_name', DB::raw('count(*) as num'))
->groupBy('book_name')
->get();
||
$users = DB::table('books')
->select(DB::raw('count(*) as num, book_name'))
->groupBy('book_name')
->get();