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 ...
随机推荐
- ASP.NET Core 6部署到IIS
1.打开IIS,新建一个网站 2.给新创建的应用程序池,设置为无托管代码,下面那个选经典或集成好像都没问题 3.运行网站,不出意外的话,会报错,提示HTTP 错误 500.19,说明网站目录权限不足, ...
- 057_Apex 开发中的问题
2019/12/27 补充内容: 1. %2F 由于页面的按钮点击或者Detail 页面编辑url中会生成 returnURL=%2F id,需要注意下 2. Trigger 中, __r 与触发条件 ...
- NTP时钟服务器(时间同步服务器)在大数据时代的重要性
NTP时钟服务器(时间同步服务器)在大数据时代的重要性 NTP时钟服务器(时间同步服务器)在大数据时代的重要性 技术交流:岳峰 15901092122 bjhrkc@126.com 大数据时代众 ...
- linux虚拟机,ifconfig无法获取静态ip地址
之前一直显示这种ip地址,如下图(网图),查看了DHCP,是正常启动的,虚拟网络编辑器中设置的也正确.后来发现更改虚拟机的设置后就可以了,如下: 设置方法:VMware-虚拟机-设置-网络适配器,选择 ...
- DAST精简代码
先训练G:先不计算D的梯度: 判别器输入类型为(源域,0)或者(目标域,1),输出图片为真实图片(源域)的概率值for param in model_D.parameters(): # model_D ...
- js中的call()、apply()、bind()方法
var a= { name:"李四", age: "五岁", text: function() { return this.name+ " " ...
- IDEA移除Maven依赖的方法
参考地址:https://blog.csdn.net/weixin_45654405/article/details/124415010 方法一: 如果不行,则进行下一步: 尝试在project St ...
- 树莓派启动后自动连接wifi
安装好系统后我们先使用 网线进行连接 使用ssh 工具连接 cd /etc/wpa_supplicant/ wpa_passphrase "网络名称" "密码" ...
- python:包含’e’和‘-’的 str 转 float
from functools import reduce def str2float(s): s = s.split('.') a = s[0] b = s[1] if a[0] == '-': a ...
- NOI 顺序查找——查找特定的值
描述 在一个序列(下标从1开始)中查找一个给定的值,输出第一次出现的位置. 输入 第一行包含一个正整数n,表示序列中元素个数.1 <= n <= 10000.第二行包含n个整数,依次给出序 ...