replaced new fct orders table

This commit is contained in:
CIEF ACC1
2023-08-23 08:13:47 +00:00
parent 2a90f2cef2
commit 991db604ff
@@ -1,13 +1,14 @@
-- AVAILALE FILTER VALUE
{% set day_use_to_churn = 61 %}
-- IMPORT
WITH companies AS (
SELECT * FROM {{ ref('dim_exchange__companies') }}
),
transaction_orders AS (
SELECT * FROM {{ ref('fct_exchange__transaction_orders') }}
SELECT * FROM {{ ref('fct_exchange__daily_orders') }}
),
@@ -18,15 +19,15 @@ remove_supplier_company AS (
FROM companies
WHERE business_type = 'IMPORTER'
),
),
order_date_row_rank AS (
SELECT
*,
row_number() OVER
(PARTITION BY transaction_orders.company_id
ORDER BY transaction_orders.order_created_datetime) AS row_rank_index
(PARTITION BY company_id
ORDER BY order_created_datetime, order_id) AS row_rank_index
FROM
transaction_orders
@@ -36,7 +37,6 @@ get_next_and_previous_order_date_orders AS (
SELECT
order_date_row_rank.*,
companies.is_migrated_company,
next_order_date_row_rank_clone.order_created_datetime AS next_order_created_datetime,
previous_order_date_row_rank_clone.order_created_datetime AS previous_order_created_datetime,
companies.company_marking_id,
companies.company_created_datetime
@@ -69,13 +69,14 @@ company_register_events AS (
remove_supplier_company.company_created_datetime,
COALESCE(MIN(transaction_orders.order_created_datetime), CURRENT_DATE())
)
>= {{day_use_to_churn}},
'Churn',
NULL) AS churn_event,
>= {{day_use_to_churn}}, 'Churn', NULL
) AS churn_event,
RTRIM(CONCAT(
RTRIM(
CONCAT(
CASE WHEN register_event IS NOT NULL THEN 'Register, ' ELSE '' END,
CASE WHEN churn_event IS NOT NULL THEN 'Churn, ' ELSE '' END ),', ' ) AS concat_event,
CASE WHEN churn_event IS NOT NULL THEN 'Churn, ' ELSE '' END ),', '
) AS concat_event,
remove_supplier_company.company_created_datetime AS event_datetime
@@ -99,17 +100,18 @@ firsttime_repeat_churn_reactive_order_events AS (
company_marking_id,
is_migrated_company,
0 AS is_never_order_company,
transaction_order_id,
order_id AS transaction_order_id,
order_status,
payment_method,
order_payment_method AS payment_method,
base_currency_id,
quote_currency_id,
base_to_quote_currency_exchange_rate,
value_rm,
tax_rm,
service_charge_rm,
IFF(is_first_time_company = 1, 'First Time Order', NULL) AS first_time_order_event,
IFF(is_first_time_company = 0, 'Repeat', NULL) AS repeat_event,
order_base_to_quote_currency_exchange_rate AS base_to_quote_currency_exchange_rate,
order_value_rm AS value_rm,
order_tax_rm AS tax_rm,
order_service_charge_rm AS service_charge_rm,
IFF(is_first_time_order_company = 1, 'First Time Order', NULL) AS first_time_order_event,
IFF(is_first_time_order_company = 0, 'Repeat', NULL) AS repeat_event,
IFF(DATEDIFF(day, order_created_datetime, COALESCE(next_order_created_datetime, CURRENT_DATE())) >= {{day_use_to_churn}}, 'Churn', NULL ) AS churn_event,
IFF(DATEDIFF(day, COALESCE(previous_order_created_datetime, company_created_datetime), order_created_datetime) >= {{day_use_to_churn}}, 'Reactive', NULL) AS reactive_event,