From 5eb597bdd2a4edfa48f629158bad9f14f448a519 Mon Sep 17 00:00:00 2001 From: Even Wei Date: Wed, 29 Nov 2023 10:33:36 +0800 Subject: [PATCH] Add rounding effect analysis Signed-off-by: Even Wei --- models/rounding_effect.sql | 6 ++++++ models/staging/stg_payments.sql | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 models/rounding_effect.sql diff --git a/models/rounding_effect.sql b/models/rounding_effect.sql new file mode 100644 index 00000000..c58b5d9b --- /dev/null +++ b/models/rounding_effect.sql @@ -0,0 +1,6 @@ +SELECT + order_id, + ROUND(amount) AS rounded_amount_dollar, + amount_cent, + (ROUND(amount) * 100 - amount_cent) AS rounding_difference_cents +FROM {{ ref('stg_payments') }} diff --git a/models/staging/stg_payments.sql b/models/staging/stg_payments.sql index 331ed487..627ee935 100644 --- a/models/staging/stg_payments.sql +++ b/models/staging/stg_payments.sql @@ -16,7 +16,8 @@ renamed as ( payment_method, -- `amount` is currently stored in cents, so we convert it to dollars - amount / 100 as amount + amount / 100 as amount, + amount as amount_cent from source