- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以我在这里有这个查询,但我不知道如何更改行为。基本上它应该从 applications 表返回一组结果,付款表中的总付款具有相应的 id,费用表中的总费用具有相应的 id。当一次支付一次费用时,它的效果非常好。但是,在有 2 笔费用的情况下,付款似乎翻了一番。我假设如果有 3 笔费用,它会增加三倍,等等。
我尝试将 sum(distinct payments.amount) 作为付款,但问题是很可能会有 2 次付款完全相同的金额。我不确定是否可以喜欢,在有与金额相对应的不同 id 的地方求和。我仍在学习 SQL。
select applications.*,
permits.title as permit,
sum(payments.amount) as payments,
sum(fees.unitprice) as fees
from applications
left join permits on applications.permitid=permits.id
left join payments on payments.appid=applications.id
left join fees on fees.appid=applications.id
where applications.deleted=0
and payments.deleted=0
and fees.deleted=0
and fees.unitPrice > 0
and applicationdate between '1975-1-1' and '2011-2-10'
group by applications.id
order by permits.deptid,permits.title,status,dateissued,applicationdate
如有任何帮助,我们将不胜感激 - 我已经尝试修复此问题好几个小时了!花了我一些时间才弄清楚是什么原因造成的。
最佳答案
您可以在派生表中进行聚合并加入到该表中。
... join (SELECT fees.appid, sum(fees.unitprice) as fees
FROM fees
WHERE fees.deleted = 0
and fees.unitPrice > 0
GROUP BY fees.appid) aggregatedfees
on aggregatedfees.appid = applications.id
...
顺便说一句:此时您的所有左联接都被您的 where 子句转换为内部联接。
关于mysql - 一个表中有 2 个结果的左连接,将相应表中的结果总和加倍,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4970630/
我正在使用Mapbox开发 map 应用程序。 我正在使用的方法使用Point(Double,Double) 获取类型不匹配要求:两次发现:两次? val lat = location
我想将 System.out 消息写入另一个 OutputStream,但我仍然想要标准输出。 我找到了类似问题的答案Copy and Redirecting System.err Stream :
我正在尝试为我正在处理的排序找到所有处理器的全局最小值和最大值。我正在尝试使用 MPI_Reduceall int rank, nproc; MPI_Comm_size(MPI_COMM_WORLD,
我想知道从一种可空类型转换为另一种“兼容”可空类型的最佳方式(从更安全和简洁的意义上说)是什么。 具体来说,从十进制转换?加倍?可以使用: public double? ConvertToNullab
我的一个表的文件大小(.MYD 文件)增加了大约 100%。如果我查看数据,就会发现过去几天的每日负载正常。是什么导致文件大小增加? myisamchk 根据用户的建议,我尝试了sudo myisam
我有一个 invoices 表。每张发票都有许多 invoice_items 和 transactions(或者,如果您愿意,也可以是“付款”)。对于每张发票,我想计算已支付金额(即其交易金额的总和)
我需要一个尽可能接近 0 的值。我需要能够除以这个值,但实际上它应该为 0。 Java 是否提供了一种简单的方法来生成仅设置最低有效位的 double ?还是必须自己计算? //编辑:一些背景信息,因
由于 Math.random ()(以及大多数伪随机数生成器,AFAIK)在 [0,1) 中生成数字: function randomInRange(min, max) { return Math
这应该很容易。相信我,我已经为此研究了几个小时。我的查询: SELECT not_piece.pid, part.name AS 'Part Name', SUM(qty_left) AS 'In S
我正在尝试传递类型为 vector > 的变量到函数 F(double ** mat, int m, int n) . F 函数来自另一个库,所以我无法更改它。有人可以给我一些提示吗?谢谢。 最佳答案
我正在尝试读取一个文件,读取它包含的字节数,然后将其四舍五入到最接近的 GB,然后将文件大小加倍。但是,有没有办法读取文件,然后将所有这些东西重新放入同一个文件中? 这是我目前所拥有的,但它创建了一个
我正在尝试传递类型为 vector > 的变量到函数 F(double ** mat, int m, int n) . F 函数来自另一个库,所以我无法更改它。有人可以给我一些提示吗?谢谢。 最佳答案
我想对超大 (200+ MB) Sqlite 文件进行一些测试。我有一些相对较小的文件 (10MB),但我想测试更大的文件。 有没有什么快速的方法/工具可以通过复制表中的数据来增加这些 Sqlite
我有一个 64 位数字,写成两个 32 位未签名的整数:unsigned int[2]。 unsigned int[0] 是 MSB,unsigned int[1] 是 LSB。我如何将它转换为 do
我需要将数量的值传递给库进行评估。 boost units library在 SI 中采用双倍值,因此 boost 单位库在确保该要求方面非常有吸引力。但是,我应该如何将数量转换为双倍值?文档和示例似
如何向 ksoap2 请求添加双重属性? request.addProperty("doubleProperty", 1.0); 网络上没有明确的答案。 最佳答案 为了将 double 值作为请求参数
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 7 年前。 Improve this qu
我正在尝试从 AngularJS 用 Swing 编写的 REST API 生成 .bin 文件。以下是代码。 var options = { url: 'http://example.com/i
我对这段代码中的特定值集有疑问。 double inputs[] = {0, -546543, 99015, 6750, 825, 2725, 70475, 50950, 42200, 675
我在 ruby on rails 应用程序中尝试为密码生成盐时遇到了 SecureRandom#hex 方法。为什么它会加倍长度参数/坚持返回的字符串长度是偶数? 最佳答案 该方法生成一个 n 字
我是一名优秀的程序员,十分优秀!