これはおそらく簡単なことですが、ドキュメントを精査しましたが、わかりません。ソーステーブルは次のとおりです。
store item date sales
101 00001 27-Oct-12 1
101 00002 27-Oct-12 0
102 00001 27-Oct-12 2
102 00002 27-Oct-12 1
101 00001 3-Nov-12 0
101 00002 3-Nov-12 0
102 00001 3-Nov-12 1
102 00002 3-Nov-12 1
...そして、たとえば商品番号 00001 だけに、店舗ごとに独自の列を持つ月間売上高のテーブルを作成するクエリを作成しようとしています--
monthyear store101sales otherstoresales
10/2012 1 2
11/2012 0 1
これが私が試したコードです--
select distinct
year(date) as SalesYear,
month(date) as SalesMonth,
sum(case when store in (101) then sales.count else 0 end) as store101sales,
sum(case when store in (102,103) then sales.count else 0 end) as otherstoresales,
from source_table
where item=00001;
GROUP BY SalesYear, SalesMonth, store101sales, otherstoresales,
ORDER BY SalesYear, SalesMonth, store101sales, otherstoresales;
助けていただければ幸いです。ありがとう!