commit wip
This commit is contained in:
parent
47d9b6f292
commit
29755961e6
1 changed files with 28 additions and 2 deletions
|
|
@ -2,7 +2,7 @@ with
|
|||
stg_resolutions__incidents as (
|
||||
select * from {{ ref("stg_resolutions__incidents") }}
|
||||
),
|
||||
comments_timeline as (
|
||||
logs_timeline as (
|
||||
select
|
||||
i.id_incident,
|
||||
(
|
||||
|
|
@ -16,8 +16,34 @@ with
|
|||
from jsonb_array_elements(i.comment_logs::jsonb) comment
|
||||
order by (comment ->> 'CreatedDate')::timestamp desc
|
||||
limit 1
|
||||
) as last_comment_date
|
||||
) as last_comment_date,
|
||||
(
|
||||
select count(*) from jsonb_array_elements(i.comment_logs::jsonb) comment
|
||||
) as comment_count,
|
||||
(
|
||||
select count(*)
|
||||
from jsonb_array_elements(i.damage_report_items::jsonb) items
|
||||
) as number_damaged_items,
|
||||
|
||||
from stg_resolutions__incidents i
|
||||
),
|
||||
damage_reported_items as (
|
||||
select
|
||||
i.id_incident,
|
||||
jsonb_array_elements(i.documents -> 'DamageReport' -> 'Items') as item
|
||||
from stg_resolutions__incidents i
|
||||
)
|
||||
damage_report_amounts as (
|
||||
select
|
||||
id_incident,
|
||||
sum((corrective_measures ->> 'Amount')::numeric) as asked_repair_amount,
|
||||
sum(
|
||||
(corrective_measures ->> 'SettlementAmount')::numeric
|
||||
) as accepted_amount,
|
||||
from
|
||||
parsed_data,
|
||||
jsonb_array_elements(item -> 'CorrectiveMeasures') as corrective_measures
|
||||
group by id_incident
|
||||
)
|
||||
|
||||
select
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue