查詢是SELECT country, count(*) as count FROM visitors GROUP BY country ORDER BY count DESC。怎么用Visitor模型寫的很有說服力?
uj5u.com熱心網友回復:
Visitor::query()->groupBy('country')->orderByDesc('count')->select('country' ,DB::raw('COUNT(1) as count'))->get()
uj5u.com熱心網友回復:
你可以嘗試這樣的事情
Visitor::select('country')
->withCount('id')
->groupBy('country')
->latest()
->get()
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/469516.html
