$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. vue项目中如何使用markdown编辑器插件

    1.安装mavon-editor $ npm install mavon-editor --save 需要使用Markdown编辑器的页面js中: import { mavonEditor } fro ...

  2. lua中self的意义

    原文链接 最近在用合宙的Air302开发物联网项目,因为合宙用的自家的luatOS操作系统,二次开发全都要用lua写,据说lua写起代码比C更方便,但是不会就是不会啊喂!!学不会就是不方便啊,例如这个 ...

  3. 微信字体大小调整导致的H5页面错乱问题处理

    当用户调整微信字体大小时会导致H5页面错乱,解决方案如下: ios:在css中加入-webkit-text-size-adjust: 100% !important;   body {   -webk ...

  4. linux(centos7)下部署jenkins

    1.安装jdk yum install -y java 确保已经安装了jdk,查看是否安装jdk命令参考地址: 2.安装jenkins 2.0添加Jenkins库到yum库,Jenkins将从这里下载 ...

  5. Test Fixture框架结构

    Test Fixture框架 1.结构: setup() testcase() teardown() 2.新建unittest文件,命名unittestdemo.py 1 import unittes ...

  6. 解决通过Eclipse启动Tomcat-Run On Server无法选择Tomcat v7.0的问题

    在eclipse中配置Tomcat并启动右键项目 -> Run As -> Run on Server可能会出现无法选择Tomcat v7.0的现象如下图,不慌菜鸟小编带你解决!1.定位到 ...

  7. pycharm 2021.3版本无法安装unittest

    不用安装unittest包,直接在类后面的括号里黏贴:unittest.TestCase,报错后点击导入unittest包即可.

  8. K Smallest In Unsorted Array

    Find the K smallest numbers in an unsorted integer array A. The returned numbers should be in ascend ...

  9. 浏览器垃圾回收机制:栈垃圾回收、堆垃圾回收、新生区老生区、Scavenge算法、标记-清除算法、标记-整理算法、全停顿、增量标记

    浏览器垃圾回收机制根据数据的存储方式分为栈垃圾回收和堆垃圾回收. 栈垃圾回收的方式非常简便,当一个函数执行结束之后,JavaScript 引擎会通过向下移动 ESP 来销毁该函数保存在栈中的执行上下文 ...

  10. Vue3父组件调用子组件内部的方法

    1. 子组件中定义方法并通过defineExpose暴露出去 import { reactive, defineExpose } from "vue"; const state = ...