laravel whereHas sum & addSelect sum
$users = User::select('id', 'username', 'coins', 'cut')
->when(request()->has('agent_tip_sum'), function ($q) {
$q->whereHas('agentBoughts', function ($q) {
$q->havingRaw('sum(agent_tip) > ' . request('agent_tip_sum'))
->groupBy('users.id');
});
})
->select('id', 'username')
->addSelect([
'agent_tip_sum' => Buy::selectRaw('sum(agent_tip)')
->whereColumn('agent_id', 'users.id')
->groupBy('agent_id')
])
->where('role', 'agent')
->get();
dd($users);
laravel whereHas sum & addSelect sum的更多相关文章
- 32. Path Sum && Path Sum II
Path Sum OJ: https://oj.leetcode.com/problems/path-sum/ Given a binary tree and a sum, determine if ...
- 有两个数组a,b,大小都为n;通过交换a,b中的元素,使sum(a)-sum(b)最小。
今天在浏览网页的时候,发现了一个叫做 华为面试题(8分钟写出代码) 的链接,不确定真实性,纯属好奇,就点进去看看 这个可能是很老的题目吧,因为我看到这题目时,底下有好多评论了.提到XX排序,内存占用 ...
- 有两个数组a,b,大小都为n,;通过交换a,b中的元素,使sum(a)-sum(b)最小。
有两个数组a,b,大小都为n,数组元素的值任意整形数,无序: 要求:通过交换a,b中的元素,使数组a元素的和与数组b元素的和之间的差最小. 当前数组a和数组b的和之差为 A = sum(a) - ...
- Path Sum,Path Sum II
Path Sum Total Accepted: 81706 Total Submissions: 269391 Difficulty: Easy Given a binary tree and a ...
- [Count the numbers satisfying (m + sum(m) + sum(sum(m))) equals to N]
Given an integer N, the task is to find out the count of numbers M that satisfy the condition M + su ...
- LeetCode之“树”:Path Sum && Path Sum II
Path Sum 题目链接 题目要求: Given a binary tree and a sum, determine if the tree has a root-to-leaf path suc ...
- 关于数论分块里r=sum/(sum/l)的证明!
今天的模拟赛里T2要使用到数论分块,里面有一个重要的坎就是关于r=sum/(sum/l)的证明,网上关于这道题的题解里都没有关于这个的证明,那么我就来填补一下: 在以下的文章里,我都会使用lo(x)表 ...
- LeetCode Two Sum&Two Sum II - Input array is sorted&3Sum&4Sum 一锅煮题解
文章目录 Two Sum Two Sum II 3Sum 4Sum Two Sum 题意 给定一个数组,和指定一个目标和.从数组中选择两个数满足和为目标和.保证有且只有一个解.每个元素只可以用一次. ...
- [LeetCode#110, 112, 113]Balanced Binary Tree, Path Sum, Path Sum II
Problem 1 [Balanced Binary Tree] Given a binary tree, determine if it is height-balanced. For this p ...
- Combination Sum,Combination Sum II,Combination Sum III
39. Combination Sum Given a set of candidate numbers (C) and a target number (T), find all unique co ...
随机推荐
- 常见DOS命令及应用
常见DOS命令使用 CMD打开方式 开始 + 系统 + 命令提示符 WIN键 + R 输入cmd + Enter WIN键 + R 输入cmd + Ctrl + Shift + Enter (管理员模 ...
- Burp Suite入门
Burpsuite Burp Suite是一个Web应用程序集成攻击平台,它包含了一系列burp工具,这些工具之间有大量接口可以互相通信,这样设计的目的是为了促进和提高整个攻击的效率.平台中所有工具共 ...
- Mac Google浏览器 Chrome
Mac Google浏览器 Chrome https://590m.com/f/28636472-500465601-d4c369 (访问密码:7410)
- TypeScript - 安装,类型
// 要使用typescript需要全局安装 通过tsc -v 来验证是否安装成功 npm i -g typescript// ts 文件中完全可以写js语法, 完全兼容js // ts 本身在运行时 ...
- java面经学习002
2. Java都有哪些map,分别怎么实现的,具体讲 3. 除了LinkedHashMap,你还知道哪些有序map 4. ConcurrentHashMap讲一讲 5. 为什么要有线程池 6. 线程池 ...
- Python面向对象编程——一些类定义(杂)
一.abstractmethod 子类必须全部实现重写父类的abstractmethod方法 非abstractmethod方法可以不实现重写 带abstractmethod方法的类不能实例化 fro ...
- pg copy用法
postgresql copy用法1,导出表数据1)导出test表数据到txt copy test to '/home/jinli/test.txt'; 2)导出test表数据到csv copy te ...
- sublime Vue、ejs、less、scss高亮展示
sublime中默认不支持ejs.vue.less.scss等文件高亮展示.解决办法可以增加对应插件: 一.安装: 1.打开sublime 2.点击 preferences ->Browse ...
- 04 ajax执行php并传递参数
做这个事情之前要导入jQuery js的方式 _this.value1 = "abc"; _this.value2 = 1; $.ajax({ url: 'xxxxxx.php', ...
- Jetpack compose学习笔记之列表(布局)
一,简介 Jetpack compose中的布局主要分为Column,Row,Box. 二,Column创建的列表 Column创建list时,不管内容是在屏幕内还是屏幕外,都会将list的内容全部创 ...