0

このcompute by句に問題があります

ステートメントは単純な選択です

Select 
    col1, sum(col2) 
from 
    table1 t1
join
    table2 t2 on t1.col1=t2.col1
where 
    year(t1.coldate) = 2012
Group by 
    col1
order by 
    col1
Compute 
    Sum(col2), avg(col2) by col1

私が取得し続けるエラーメッセージは

メッセージ 411、レベル 16、状態 1、行 1
COMPUTE 句 #1、集計式 #1 は選択リストにありません..

ここに私の完全なコードsqlfiddleがあります

私が欲しいのは、2012年に薬が販売された年であるTransactionIDとTotalMedicine(販売された薬の数量から派生)を表示することでした。また、薬の数と平均販売数を数えます。

4

2 に答える 2

0

句を一致させる必要があるため、次を試してください。

Select 
    col2, sum(col2)  
from 
    table1 t1 
join 
    table2 t2 on t1.col1 = t2.col1 
where 
    year(t1.coldate) = 2012 
Group by 
    col1 
order by
    col1 
Compute 
    Sum(col2), avg(col2) by col1

または同様のもの、正確な答えを提供しますが、詳細が必要です。

于 2013-05-26T15:05:12.713 に答える