DatabaseCreation: Customer SMS history.sql

File Customer SMS history.sql, 1.7 KB (added by 231045, 2 weeks ago)
Line 
1create view public.v_customer_sms_history
2 (customer_id, customer_name, email, account_number, subscription_number, plan_name, contract_number,
3 contract_status, sms_cdr_id, from_number, to_number, sent_at, sms_type, direction, charge_amount,
4 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 sms.sms_cdr_id,
15 sms.source_msisdn AS from_number,
16 sms.destination_msisdn AS to_number,
17 sms.event_time AS sent_at,
18 sms.sms_type,
19 sms.direction,
20 sms.charge_amount,
21 CASE
22 WHEN sms.roaming_partner_id IS NOT NULL THEN true
23 ELSE false
24 END AS is_roaming,
25 COALESCE(rp.country, 'Home'::text) AS network_country
26FROM customers c
27 JOIN accounts a ON a.customer_id = c.customer_id
28 JOIN subscriptions s ON s.account_id = a.account_id
29 JOIN plans p ON p.plan_id = s.plan_id
30 LEFT JOIN contracts con ON con.contract_id = s.contract_id
31 JOIN usage_cdr_sms sms ON sms.subscription_id = s.subscription_id
32 LEFT JOIN roaming_partners rp ON rp.roaming_partner_id = sms.roaming_partner_id;
33
34alter table public.v_customer_sms_history
35 owner to postgres;