sql - 语法错误:应为“(”或“,”或关键字 SELECT,但在 [23:1] 获得标识符“rfm”
问题描述
寻求支持来解决这个问题。我收到如下错误 语法错误:预期“(”或“,”或关键字 SELECT 但在 [23:1] 获得标识符“rfm”
with combinedtable as (
-- get user id, purchase Delivery_Date and purchase Subtotal from main data table
select
maintable.Customer_id,
maintable.Delivery_Date,
recentDelivery_Date.recent_Delivery_Date,
sum(maintable.Subtotal) as Subtotal,
count(maintable.Customer_id) as totalevents
from `piattosteakhouse.ALFACO.Ordering_Co_Orders` as maintable
-- replace <your table> with your data table.
-- get the Delivery_Date of last purchase for each user and join it with maintable to get the last purchase CDelivery_Date
join
(
SELECT
Customer_id,
max(Delivery_Date) as recent_CDelivery_Date
from maintable
group by 1
) as recentCDelivery_Date
on maintable.Customer_id = recentCDelivery_Date.Customer_id
group by 1,2,3
)
rfm as (
select
Customer_id,
Delivery_Date_DIFF(current_CDelivery_Date(),recent_CDelivery_Date,day) as recency,
count(Customer_id) as frequency,
sum(Subtotal) as monetary
from combinedtable
group by 1,2
order by recency
)
-- show final table.
select * from rfm