【发布时间】:2018-04-26 08:11:09
【问题描述】:
我的查询情况很奇怪。我的目标是显示每个人的多笔交易的总存款和取款并显示出来。我得到了多行,我需要合并为一行。这一切都需要在一个查询中完成
SELECT
lastname,
firsname,
case when upper(category) = 'W' then sum(abs(principal)) end as Withdrawal,
case when upper(category) = 'D' then sum(abs(principal)) end as Deposit,
description
FROM
table1
JOIN table2 ON table1.id = table2.id
JOIN table3 ON table2.c = table3.c
WHERE
description = 'string'
GROUP BY
lastname,
firstname,
description,
category
我的结果是
lastname firstname Withdrawal Deposit description
john smith null 140.34 string
john smith 346.00 null string
jane doe null 68.03 string
jane doe 504.00 null string
我正在寻找
lastname firstname Withdrawal Deposit description
john smith 346.00 140.34 string
jane doe 504.00 68.03 string
将委托人添加到组中不起作用。任何解决此问题的帮助将不胜感激!
【问题讨论】:
-
从分组依据中删除类别并在案例外求和?