製品の場所について定義済みのケースを作成しており、後でそのケースを値として返したいと考えています。しかし、「'フィールド リスト' の列の位置が不明です」というエラーが表示されます。
SELECT location, avg(pcnt), max(pcnt), min(pcnt)
FROM (
-- create temporary table 'a' to serve data from inner typing table created below
SELECT a.date_key, a.num_snowflakes/k.tot_snowflakes AS pcnt
FROM (
SELECT
date_key,
CASE
WHEN location_type_key=2 then 'at_customer'
WHEN location_type_key IN (1,13) then 'on_floor'
WHEN location_type_key IN (6,7,11) then 'sat1'
WHEN location_type_key IN (4,5) then 'film'
WHEN location_type_key IN (8,9) then 'repair'
WHEN location_type_key IN (12) then 'inspection'
WHEN location_type_key IN (2) then 'outside'
ELSE NULL END AS location,
COUNT(distinct garment_key) AS num_snowflakes,
COUNT(distinct product_key) AS num_skus
FROM database
-- excluding vendor return and retired
WHERE location_type_key NOT IN (3,10)
-- between 6/15/13 and 8/15/13
AND date_key >= 20130615 AND date_key <= 20130815
-- aggregates by day and location case
GROUP BY date_key, location
) AS a
JOIN
-- create temporary table 'k' to serve 'tot_snowflakes' to table 'a' above
(SELECT b.date_key, sum(b.num_snowflakes) AS tot_snowflakes
FROM (
SELECT
date_key,
CASE
WHEN location_type_key=2 then 'at_customer'
WHEN location_type_key IN (1,13) then 'on_floor'
WHEN location_type_key IN (6,7,11) then 'sat1'
WHEN location_type_key IN (4,5) then 'film'
WHEN location_type_key IN (8,9) then 'repair'
WHEN location_type_key IN (12) then 'inspection'
WHEN location_type_key IN (2) then 'outside'
ELSE NULL END AS location,
COUNT(distinct garment_key) AS num_snowflakes,
COUNT(distinct product_key) AS num_skus
FROM database
WHERE location_type_key NOT IN (3,10)
-- between 6/15/13 and 8/15/13
AND date_key >= 20130615 AND date_key <= 20130815
-- aggregates by day and location case
GROUP BY date_key, location
) AS b
) AS k
ON a.date_key=k.date_key
GROUP BY a.date_key, a.location
) AS z
常に正しいテーブルを呼び出していることを確認しようとしたため、エラーの原因がわかりません。誰にもアイデアはありますか?
ありがとうございました!