我有带有name
和no_of_sell
列的产品表。
我想根据商品表中的no_of_sell
列获得销量最高的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
最佳答案
因此,如果我在no_of_sell
列中正确理解它,则为整数。我应该这样写:
$best_sell = DB::table('products')
->orderBy('no_of_sell', 'desc')
->limit(5)
->where('products.status','=','1')
->paginate(4)
->get();
https://laravel.com/docs/5.4/queries#retrieving-results
https://laravel.com/docs/5.4/queries#ordering-grouping-limit-and-offset
关于php - 如何从列中获取最高的5个值?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45328367/