laravel - Laravel - 如何在 Eloquent Top 5 查询中添加 where 子句
问题描述
我正在使用 Laravel-5.8 Eloquent Query,如下所示:
$destination = Trip::select('destination')
->selectRaw('COUNT(*) AS count')
->groupBy('destination')
->orderByDesc('count')
->limit(5)
->get();
如何将其包含在上面的查询中?
其中client_id = $userClientId
解决方案
您可以直接使用where
before group by 或 after。
$destination = Trip::select('destination')
->selectRaw('COUNT(*) AS count')
->where('client_id', $userClientId)
->groupBy('destination')
->orderByDesc('count')
->limit(5)
->get();
推荐阅读
- javascript - 将不存在的变量从 PHP 传递到 JavaScript 时出现语法错误
- vb.net - 如何找到不同类型的 datagridviewcell 或 datagridviewcolumn(运行时创建)
- javascript - Angular 6+ - 使用输入文本过滤器处理关键事件
- node.js - Node.JS 中间件登录
- arrays - 将 Array[Array[String]] 的 RDD 转换为 DataFrame
- python - Python:计算列表并显示计数范围
- c# - 前缀过滤器的 HBase Shell 比 Restful 端点快近 100 倍
- java - 如何使用 XPath 读取 xlink:label 值
- python-3.x - Python List - 更改字符并保持相同的顺序
- mongodb - Mongodb根据动态字段和静态字段对文档进行排序