mirror of
https://gitlab.com/cief-data/dbt_cloud.git
synced 2026-08-19 04:14:00 +00:00
39 lines
786 B
SQL
39 lines
786 B
SQL
--IMPORT
|
|
WITH contacts AS (
|
|
SELECT * FROM {{ ref('stg_exchange__contacts') }}
|
|
),
|
|
|
|
--LOGIC
|
|
get_latest_company_contacts AS (
|
|
SELECT
|
|
*,
|
|
row_number() OVER
|
|
(PARTITION BY company_id
|
|
ORDER BY contact_created_datetime DESC) AS last_row_number
|
|
|
|
FROM contacts
|
|
|
|
QUALIFY
|
|
last_row_number = 1
|
|
),
|
|
|
|
--FINAL
|
|
final__int_exchange__latest_company_contacts AS (
|
|
SELECT
|
|
id,
|
|
company_id,
|
|
country_id,
|
|
country_name,
|
|
reference,
|
|
phone,
|
|
email,
|
|
wechat_id,
|
|
contact_deleted_datetime,
|
|
contact_created_datetime,
|
|
contact_updated_datetime
|
|
|
|
FROM get_latest_company_contacts
|
|
)
|
|
|
|
SELECT * FROM final__int_exchange__latest_company_contacts
|