Trying to solve for the issue in this query when creating a query table in Analytics. Getting an error message "Encountered AS" in Line 2.
SELECT "Completed Jobs - Structure".*
WITH RankedData AS (
SELECT
"JOB#",
"BDM Total Commission Earned",
ROW_NUMBER() OVER (PARTITION BY "JOB#" ORDER BY "Date Closed") AS rn
FROM "Completed Jobs - Structure"
)
SELECT
a1."JOB#",
a1."BDM Total Commission Earned" AS current_value,
COALESCE(a1."BDM Total Commission Earned" - a2."BDM Total Commission Earned", 0) AS value_difference
FROM RankedData a1
LEFT JOIN RankedData a2 ON a1."JOB#" = a2."JOB#" AND a1.rn = a2.rn + 1;
Any help would be appreciated!