作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用此查询来获取:来自 tblcustomers 的客户名称每个客户的 tbltransactions 交易金额总和
select a.customerid, sum(transactionamount) as transactionamount ,b.customername
from tbltransactions a
join tblcustomers b using (customerid)
group by a.customerid
order by b.customername
tbltransactions
中的 transactionamount
列包含客户购买的正值和客户付款的负值。
如何在此查询中获取此表达式每个客户的 min(transactionamount) < 0?
编辑:min(transactionamount) < 0 给出每个客户迄今为止支付的最大金额
最佳答案
您可以使用条件聚合来做到这一点:
select a.customerid, sum(transactionamount) as transactionamount, b.customername,
min(case when transactionamount < 0 then transactionamount end) as BiggestPayment
from tbltransactions a join
tblcustomers b
using (customerid)
group by a.customerid
order by b.customername;
请注意,小于 0 的最小值实际上是最小值而不是最大值。
编辑:
在这种情况下,我将使用 substring_index()
/group_concat()
技巧找到最新的付款日期:
substring_index(group_concat((case when transactionamount < 0 then transactionamount end)
order by transactiondate desc
), ',', 1)
关于mysql - 如何在mysql查询中得到想要的结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24450873/
使用登录后,我想吐出用户名。 但是,当我尝试单击登录按钮时, 它给了我力量。 我看着logcat,但是什么也没显示。 这种编码是在说。 它将根据我在登录屏幕中输入的名称来烘烤用户名。 不会有任何密码。
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎是题外话,因为它缺乏足够的信息来诊断问题。 更详细地描述您的问题或include a min
我是一名优秀的程序员,十分优秀!