php - Laravel 雄辩的查询以获取特定日期后仅用户的数据
问题描述
我有数据库表,有business_name 和user_id 以及created_at 和updated_at,现在我想查询数据,我将只获得那些user_ids 且只有created_at 大于特定日期的业务。
Business::where('created_at', '>' , new \DateTime('2020-08-30'))->distinct('user_id')->get();
现在这个查询返回 created_at 大于这个日期的记录,但我想要 user_id 只在此之后创建业务并且在此日期之前没有其他记录。
解决方案
Business::whereRaw('MIN(created_at) > ' . new \DateTime('2020-08-30'))->distinct('user_id')->get();
推荐阅读
- java - 用 Java 流替换嵌套循环
- r - 我的 Shiny App 在本地工作,但在 shinyapps.io 上不工作
- javascript - Chrome 扩展上下文菜单项不可见
- netlogo - 如何实现需要以某种有序方式分布在海龟之间的守恒量?
- java - 在 JTextArea 中对单词进行排序
- firebase - 具有多个firebase请求的flutter bloc cubit最佳实践
- google-chrome-extension - 如何为 Chrome 链接到文本片段 URL 添加书签?
- html - 需要缩放 SVG 帮助
- python - python有没有办法通过从conf文件中读取源目录和目标目录来移动windows上的文件?
- html-table - Material UI 创建多行数据表行