select sum(t.amount)
from
(select yearquarter,
(case when sum(case when type not in (3, 4) then 1 else 0 end) = 0
then sum(amount)
else sum(case when type not in (3, 4) then amount else 0 end)
end)
from t
where status = 'A'
group by yearquarter)t;
需要总结"金额"来自内部案例陈述,但获得错误
答案 0 :(得分:1)
您没有在t子查询中命名amount列。
select sum(t.amount)
from
(select yearquarter,
(case when sum(case when type not in (3, 4) then 1 else 0 end) = 0
then sum(amount)
else sum(case when type not in (3, 4) then amount else 0 end)
end) AS amount
from t
where status = 'A'
group by yearquarter)t;