2017-08-28 5 views
0
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; 

必要性値を合計しようとすると、エラーを投げるが、あなたはあなたのトンのサブクエリで金額欄に名前を付けていなかったインナーケースステートメントは、内側case文から「量」を総括する

+0

実際にここで何をしようとしていますか? –

+0

エラー:メッセージ8155、レベル16、状態2、行13 't'の列2に列名が指定されていません。 msg 207、レベル16、状態1、行1 'amount'列名が無効です。 –

+0

case文の2つのcase "amount"を1つに追加しようとしています –

答えて

1

エラーを取得しています。

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; 
+0

混乱を避けるために、外部エイリアスを別の名前にする必要があります。私の+1。 –

関連する問題