$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. IntelliJ IDEA 生成serialVersionUID

    1.设置Settings-->Editor->Inspections 2.实现Serializble

  2. spring boot读取本地文件

    File file = ResourceUtils.getFile("classpath:face/1112.txt"); InputStream inputStream = ne ...

  3. (jmeter笔记)jmeter远程启用服务器(分布式)

    1.在负载机上安装jmeter,修改jmeter\bin\jmeter.properties配置: 1)server.rmi.ssl.disable=false 改 server.rmi.ssl.di ...

  4. go 死锁示例

    以下代码不会有任何打印.原因是:channel ch 在make 时是无缓冲区的channel.无缓冲区的channel 发送一个数据进入后需要等待这个数据被消耗才能继续发送下一个数据.然而getFr ...

  5. ES6 - Class - 继承

    Class 其实是一个语法糖,他能实现的,ES5同样能实现 ES5 //手机 function Phone(brand,price){ this.brand = brand; this.price = ...

  6. jquery获取父级容器高度

    //获取浏览器显示区域的高度console.log( $(window).height()); //获取浏览器显示区域的宽度console.log($(window).width()); //获取页面 ...

  7. NTP时钟服务器(时间同步服务器)在大数据时代的重要性

    NTP时钟服务器(时间同步服务器)在大数据时代的重要性 NTP时钟服务器(时间同步服务器)在大数据时代的重要性 技术交流:岳峰 15901092122 bjhrkc@126.com    大数据时代众 ...

  8. curl从入门到精通教程

    直接看英文版 https://catonmat.net/cookbooks/curl

  9. 手把手教你用Burpsuite+夜神模拟器抓安卓(Android 7)http+https包

    (1)进入正题,bp证书下载(下载证书至电脑):打开bp,配置好代理,浏览器访问http://127.0.0.1:8080 下载证书,记住保存路径,注意别修改证书后缀(der)!!! (2)准备一个L ...

  10. noi 1.5 28 分离整数的各个数位

    描述 给定一个整数,要求从个位开始分离出它的每一位数字. 输入 输入一个整数,整数在1到100000000之间. 输出 从个位开始按照从低位到高位的顺序依次输出每一位数字.数字之间以一个空格分开. 样 ...