Я пытаюсь запустить код ниже на Snowflake:
SELECT
agg_zone_delivery_metrics_hourly.zone_code,
agg_zone_delivery_metrics_hourly.start_of_period_local_date,
MIN(CASE WHEN azdmh.start_of_period_local_hour_of_day = '18' THEN agg_zone_delivery_metrics_hourly.throughput_actual END) AS TP18,
MIN(CASE WHEN azdmh.start_of_period_local_hour_of_day = '19' THEN agg_zone_delivery_metrics_hourly.throughput_actual END) AS TP19,
MIN(CASE WHEN azdmh.start_of_period_local_hour_of_day = '20' THEN agg_zone_delivery_metrics_hourly.throughput_actual END) AS TP20
FROM (
SELECT
CAST(EXTRACT(HOUR FROM CAST(agg_zone_delivery_metrics_hourly.START_OF_PERIOD_LOCAL AS TIMESTAMP)) AS INT) AS "azdmh.start_of_period_local_hour_of_day",
TO_CHAR(TO_DATE(agg_zone_delivery_metrics_hourly.START_OF_PERIOD_LOCAL ), 'YYYY-MM-DD') AS "agg_zone_delivery_metrics_hourly.start_of_period_local_date",
agg_zone_delivery_metrics_hourly.ZONE_CODE AS "agg_zone_delivery_metrics_hourly.zone_code",
nullif(sum(agg_zone_delivery_metrics_hourly.orders_delivered), 0) / nullif(sum(agg_zone_delivery_metrics_hourly.rider_hours_worked_dhw_sum), 0)
AS "agg_zone_delivery_metrics_hourly.throughput_actual"
FROM tblB AS agg_zone_delivery_metrics_hourly
WHERE ((((agg_zone_delivery_metrics_hourly.START_OF_PERIOD_LOCAL ) >= ((DATEADD('day', -7, DATE_TRUNC('week', DATE_TRUNC('day', CONVERT_TIMEZONE('UTC', 'Hongkong', CAST(CURRENT_TIMESTAMP() AS TIMESTAMP_NTZ))))))) AND (agg_zone_delivery_metrics_hourly.START_OF_PERIOD_LOCAL ) < ((DATEADD('day', 7, DATEADD('day', -7, DATE_TRUNC('week', DATE_TRUNC('day', CONVERT_TIMEZONE('UTC', 'Hongkong', CAST(CURRENT_TIMESTAMP() AS TIMESTAMP_NTZ))))))))))) AND (((CASE TO_CHAR(agg_zone_delivery_metrics_hourly.START_OF_PERIOD_LOCAL , 'DY')
WHEN 'Tue' THEN 'Tuesday'
WHEN 'Wed' THEN 'Wednesday'
WHEN 'Thu' THEN 'Thursday'
WHEN 'Sat' THEN 'Saturday'
ELSE TO_CHAR(agg_zone_delivery_metrics_hourly.START_OF_PERIOD_LOCAL , 'DY') || 'day' END) = 'Sunday')) AND (CAST(EXTRACT(HOUR FROM CAST(agg_zone_delivery_metrics_hourly.START_OF_PERIOD_LOCAL AS TIMESTAMP)) AS INT) IN (20,18,19)) AND (agg_zone_delivery_metrics_hourly.COUNTRY_NAME = 'Hong Kong') AND agg_zone_delivery_metrics_hourly.is_within_zone_hours AND (agg_zone_delivery_metrics_hourly.COUNTRY_NAME = 'Hong Kong')
GROUP BY 1,TO_DATE(agg_zone_delivery_metrics_hourly.START_OF_PERIOD_LOCAL ),3) AS tblA
Однако я получаю сообщение об ошибке ниже:
SQL compilation error: error line 2 at position 0 invalid identifier 'AGG_ZONE_DELIVERY_METRICS_HOURLY.ZONE_CODE'
Я считаю, что проблема заключается в том, что код невозможность распознавать псевдоним столбца из подзапроса.