我有產品表name
和no_of_sell
列.. 我想根據no_of_sell
列從產品表中獲得最高5的銷售產品。 如何將它與查詢生成器一起使用?如何從列中獲得最高5個值?
$propular_products = DB::table('users')
->join('products','products.auth_id','users.id')
->select('products.*')
->orderBy('products.no_of_sell', 'desc')
->where('products.status','=','1')
->paginate(5);
假設products
表:
name no_of_sell
x 6
y 9
z 10
t 23
u 3
h 11
r 5
我想找到
products list of 5 max no_of_sell ie, x y z t h
您可以使用排序依據[https://laravel.com/docs/5.4/queries#ordering-grouping-limit (https://laravel.com/docs/5.4/queries#ordering-grouping-limit-and-offset) –