DatabaseCreation: Customer call history.sql

File Customer call history.sql, 2.0 KB (added by 231045, 2 weeks ago)
Line 
1create view public.v_customer_call_history
2 (customer_id, customer_name, email, account_number, subscription_number, plan_name, contract_number,
3 contract_status, call_cdr_id, from_number, to_number, call_started_at, call_ended_at, duration_minutes,
4 call_type, direction, charge_amount, is_roaming, network_country)
5as
6SELECT c.customer_id,
7 COALESCE((c.first_name || ' '::text) || c.last_name, c.company_name) AS customer_name,
8 c.email,
9 a.account_number,
10 s.subscription_number,
11 p.plan_name,
12 con.contract_number,
13 con.status AS contract_status,
14 cdr.call_cdr_id,
15 cdr.originating_msisdn AS from_number,
16 cdr.destination_msisdn AS to_number,
17 cdr.event_start_time AS call_started_at,
18 cdr.event_end_time AS call_ended_at,
19 round(cdr.duration_seconds::numeric / 60.0, 2) AS duration_minutes,
20 cdr.call_type,
21 cdr.direction,
22 cdr.charge_amount,
23 CASE
24 WHEN cdr.roaming_partner_id IS NOT NULL THEN true
25 ELSE false
26 END AS is_roaming,
27 COALESCE(rp.country, 'Home'::text) AS network_country
28FROM customers c
29 JOIN accounts a ON a.customer_id = c.customer_id
30 JOIN subscriptions s ON s.account_id = a.account_id
31 JOIN plans p ON p.plan_id = s.plan_id
32 LEFT JOIN contracts con ON con.contract_id = s.contract_id
33 JOIN usage_cdr_calls cdr ON cdr.subscription_id = s.subscription_id
34 LEFT JOIN roaming_partners rp ON rp.roaming_partner_id = cdr.roaming_partner_id;
35
36alter table public.v_customer_call_history
37 owner to postgres;