$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的更多相关文章

  1. 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 ...

  2. 有两个数组a,b,大小都为n;通过交换a,b中的元素,使sum(a)-sum(b)最小。

    今天在浏览网页的时候,发现了一个叫做  华为面试题(8分钟写出代码) 的链接,不确定真实性,纯属好奇,就点进去看看 这个可能是很老的题目吧,因为我看到这题目时,底下有好多评论了.提到XX排序,内存占用 ...

  3. 有两个数组a,b,大小都为n,;通过交换a,b中的元素,使sum(a)-sum(b)最小。

    有两个数组a,b,大小都为n,数组元素的值任意整形数,无序: 要求:通过交换a,b中的元素,使数组a元素的和与数组b元素的和之间的差最小. 当前数组a和数组b的和之差为    A = sum(a) - ...

  4. Path Sum,Path Sum II

    Path Sum Total Accepted: 81706 Total Submissions: 269391 Difficulty: Easy Given a binary tree and a ...

  5. [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 ...

  6. 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 ...

  7. 关于数论分块里r=sum/(sum/l)的证明!

    今天的模拟赛里T2要使用到数论分块,里面有一个重要的坎就是关于r=sum/(sum/l)的证明,网上关于这道题的题解里都没有关于这个的证明,那么我就来填补一下: 在以下的文章里,我都会使用lo(x)表 ...

  8. LeetCode Two Sum&Two Sum II - Input array is sorted&3Sum&4Sum 一锅煮题解

    文章目录 Two Sum Two Sum II 3Sum 4Sum Two Sum 题意 给定一个数组,和指定一个目标和.从数组中选择两个数满足和为目标和.保证有且只有一个解.每个元素只可以用一次. ...

  9. [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 ...

  10. 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 ...

随机推荐

  1. nginx的nginx.conf目录简单配置

    我的nginx.conf是在  etc/nginx/目录下 我是直接在http随便找了个地方添加如下代码的: server { listen 8066; server_name 192.168.0.2 ...

  2. iOS开发之检测项目是否包含UIWebView

    应苹果审核要求不能包含UIWebView,所以我们上线之前应该扫一下项目是否包含UIWebView 我们直接打开终端 cd 到工程文件下面 执行命令 grep -r UIWebView .  在扫描结 ...

  3. pg copy用法

    postgresql copy用法1,导出表数据1)导出test表数据到txt copy test to '/home/jinli/test.txt'; 2)导出test表数据到csv copy te ...

  4. js操作网页元素

    二.操作网页元素 1.查找网页元素 给标签设置id属性,一个网页中id的值不能出现重复的 <button id="btn">按钮</button> 2.给按 ...

  5. 浏览器输入URL发生了什么:DNS解析、TCP握手、HTTP缓存、重定向、服务器状态码、渲染引擎和JS引擎互斥、渲染过程、浏览器进程、网络进程、渲染进程

    输入地址,浏览器查找域名的 IP 地址. 浏览器向 该 IP 地址的web 服务器发送一个 HTTP 请求, 在发送请求之前浏览器和服务器建立TCP的三次握手,判断是否是HTTP缓存, 如果是强制缓存 ...

  6. PHP Redis 基本命令

    连接到 redis 服务 //连接本地的 Redis 服务 $redis = new Redis(); $redis->connect('127.0.0.1', 6379);//查看服务是否运行 ...

  7. js 导出excle文件(多页)

      --前提:页面生成相应的表格数据    例如: <table id="a"> <tr> <th></th> </tr> ...

  8. Leetcode209

    209. Minimum Size Subarray Sum         i , s , l = 0, 0, 0         for j in range(len(nums)):        ...

  9. Tomcat启动—本地文件夹

    打开tomcat文件夹 打开bin目录 在路径这里输入cmd 就可以直接跳转到当前页面下 接下来我们在cmd命令中启动startup.bat (记得设置java环境变量) 这里我没设置utf-8 我无 ...

  10. PageHeplper使用

    1.引入POM 1 <dependency> 2 <groupId>com.github.pagehelper</groupId> 3 <artifactId ...