$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. ORACLE 创建只读用户

    create user cxuser01 identified by test123  default tablespace USERS temporary tablespace TEMP; --创建 ...

  2. Unity 纯C# 完成 APK从下载到 自安装

    最简单的就是用androidStudio 进行编辑,打个aar 包,在Unity中调用方法,很便捷以下内容均转载Unity论坛,Android API24版本下可用,android API 24以上版 ...

  3. cheerio中文文档

    这篇参考手册是对cheerio 官方文档的中文翻译 cheerio是jquery核心功能的一个快速灵活而又简洁的实现,主要是为了用在服务器端需要对DOM进行操作的地方 简介   让你在服务器端和htm ...

  4. python菜鸟学习: 1.用户登录输入输出

    # -*-coding: utf-8 -*-name = 'liyuzhoupan'password = '123'def login_test(): count = 0 while count &l ...

  5. 全局 使用 stylus 变量

    首先 安装 啦 npm i stylus stylus-loader -D 之后 使用全局变量 然后在组件中引用改变量  -->没有用! 原因还没有在build/utils.js文件 全局引入 ...

  6. SpringMVC-nfjh

    SpringMVC springmvc项目创建 1.使用maven创建web项目结构 2.补充更改结构 3.springmvc-config.xml 1)添加包扫描(context命名空间) 2)添加 ...

  7. UNIT ONE

    一.机器语言 1.机器指令         0与1构成 2.机器可以直接执行 二.汇编语言 1.汇编指令       要翻译成机器指令,机器才可以运行 2.给人看的,主要是人看得懂 VS 机器.汇编. ...

  8. vmware workstation 16.x安装windows server 2012 R2无法点击安装vmware tools选项

    在使用vmware workstation预设安装windows server 2012 R2后,提示需要先升级KBxxxxx更新才可以安装vmware tools,但是在安装了所需的更新后,发现菜单 ...

  9. vscode python配置pip源

    更换到国内清华园 C盘-User-用户名-新建"pip"文件夹-新建"pip.ini"文件 pip.ini 文件中内容: [global]index-url = ...

  10. java中锁的应用(ReentrantLock)

    package com.xielu.test; public class explicit { private static Lock lock = new ReentrantLock(); priv ...