Changed the logic for the model
This commit is contained in:
parent
84f2156c99
commit
35e7144efd
3 changed files with 43 additions and 20 deletions
42
models/intermediate/cross/int_deals_consolidation.sql
Normal file
42
models/intermediate/cross/int_deals_consolidation.sql
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
with
|
||||
int_xero__contacts as (select * from {{ ref("int_xero__contacts") }}),
|
||||
int_core__unified_user as (select * from {{ ref("int_core__unified_user") }}),
|
||||
int_hubspot__deal as (select * from {{ ref("int_hubspot__deal") }}),
|
||||
ranked_core_deals as (
|
||||
select
|
||||
id_deal,
|
||||
company_name as core_company_name,
|
||||
row_number() over (partition by id_deal order by company_name) as row_num
|
||||
from intermediate.int_core__unified_user
|
||||
where id_deal is not null
|
||||
),
|
||||
deals_core as (
|
||||
select id_deal, core_company_name from ranked_core_deals where row_num = 1
|
||||
),
|
||||
ranked_hubspot_deals as (
|
||||
select
|
||||
id_deal,
|
||||
deal_name as hubspot_deal_name,
|
||||
row_number() over (partition by id_deal order by deal_name) as row_num
|
||||
from intermediate.int_hubspot__deal
|
||||
where id_deal is not null
|
||||
),
|
||||
deals_hubspot as (
|
||||
select id_deal, hubspot_deal_name from ranked_hubspot_deals where row_num = 1
|
||||
),
|
||||
ranked_xero_deals as (
|
||||
select
|
||||
id_deal,
|
||||
contact_name as xero_contact_name,
|
||||
row_number() over (partition by id_deal order by contact_name) as row_num
|
||||
from intermediate.int_xero__contacts
|
||||
where id_deal is not null
|
||||
),
|
||||
deals_xero as (
|
||||
select id_deal, xero_contact_name from ranked_xero_deals where row_num = 1
|
||||
)
|
||||
|
||||
select *
|
||||
from deals_core
|
||||
full outer join deals_hubspot using (id_deal)
|
||||
full outer join deals_xero using (id_deal)
|
||||
Loading…
Add table
Add a link
Reference in a new issue