【发布时间】:2017-11-21 09:24:05
【问题描述】:
我正在处理一个查询,我需要在各种条件下找到总和。现在我的查询是:
select
sum(case when condition then A_amount end) as S_A_amount,
sum(case when condition then B_amount end) as S_B_amount
但在第三种情况下,我还需要在 When 条件下使用 sum 函数
sum(case when sum(C_amount)>3 then 6 else sum(C_amount) end) as S_C_amount
from table A group by item
我无法实现第三个条件。我收到not a single group-by 错误。
【问题讨论】:
-
请添加示例数据。
-
为什么?不需要样品。只需要一个子查询来计算 SUM(C_amount)