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 ...
随机推荐
- vue项目中配置svg图标 cli3路径
1 添加依赖 npm install svg-sprite-loader file-loader -D 2 在components目录下新增一个IconSvg.vue文件 <template&g ...
- DNS服务器(简)
服务端:192.168.182.187 客户端:192.168.182.16 windows客户端:192.168.182.17 1.安装相关服务 yum -y install bind bind-c ...
- 记——flask实现全文搜索
参考: flask入门和进阶十(实现全文搜索)已解决:https://blog.csdn.net/chengmo123/article/details/100552287 一.首先安装flask-wh ...
- 关于Easyui和JQuery版本兼容IE8问题记录
1.最后支持IE8及以下版本的是JQuery1.9 2.最后支持IE8及以下的Easyui是1.3.2,其对应的是JQuery1.8 因为低版本的Easyui,缺少某些方便好用的属性方法和样式不好看, ...
- 【python】类的学习
https://www.bilibili.com/video/av69455439?from=search&seid=406401960648305052 https://zhuanlan.z ...
- Python openpyxl【包】
介绍 Excel是我们日常工作中经常用到的办公软件,在处理数据和表格方面有着优异的性能,那么能不能用python来操作Excel呢? 答案是肯定的,openpyxl是一个第三方库,可以处理xlsx格式 ...
- DML操作数据
添加数据 insert into 表名(列的名称)(数据);ps:列的名称用` `包围可以减少出错 添加全部数据的时候可以把列的名称省略: 修改数据 update 表名 set 列名=数据,列名= ...
- 每日一题_1_x^n
函数头为double power(double x,int n).在主函数中输入x.n并调用该函数求 (函数定义在主函数后面,在调用前做函数声明) 输出x^n 1 #define _CRT_SECUR ...
- React中的CSS模块
CSS模块 使用步骤: 1.新建一个XXX.moudle.css文件 2.在组件中引入css impor classes(变量) fro ...
- git在linux安装步骤详解!!
linux上安装,以centos 7.x为例 yum命令安装 yum install gityum install 安装的git不是最新版本,如需最新版本需要自行编译 到下面的网站下载合适的版本 ht ...