訂單成長率
Bob 還需要最後一張圖表來完成他的簡報投影片。他已經涵蓋了 Delivr 的新使用者成長、MAU 持續上升,以及高留存率。不過還少了點什麼。整份投影片裡,竟然沒有提到評估使用者活動最重要的指標:使用者的訂單!使用者下的訂單越多,就代表他們在 Delivr 上越活躍,Delivr 帶來的收入也就越高。
請把按月比較(MoM)的訂單成長率表格傳給 Bob。
(「回顧」:MoM 指的是 month-on-month,亦即按月相比。)
本練習屬於課程
使用 SQL 分析商業資料
練習說明
- 計算每個月份的唯一訂單數量。
- 取得各月份的上月與本月訂單數。
- 輸出一個按月比較(MoM)的訂單成長率表格。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
WITH orders AS (
SELECT
DATE_TRUNC('month', order_date) :: DATE AS delivr_month,
-- Count the unique order IDs
___ AS orders
FROM orders
GROUP BY delivr_month),
orders_with_lag AS (
SELECT
delivr_month,
-- Fetch each month's current and previous orders
___,
COALESCE(
___,
1) AS last_orders
FROM orders)
SELECT
delivr_month,
-- Calculate the MoM order growth rate
ROUND(
___,
2) AS growth
FROM orders_with_lag
ORDER BY delivr_month ASC;