DatabaseCreation: Customer full usage activity.sql

File Customer full usage activity.sql, 1.3 KB (added by 231045, 2 weeks ago)
Line 
1create view public.v_customer_usage_360_summary
2 (customer_id, customer_name, account_number, subscription_number, plan_name, total_call_seconds,
3 total_call_minutes, total_sms, total_data_used_gb, total_usage_charges)
4as
5SELECT c.customer_id,
6 COALESCE((c.first_name || ' '::text) || c.last_name, c.company_name) AS customer_name,
7 a.account_number,
8 s.subscription_number,
9 p.plan_name,
10 sum(uad.total_call_seconds) AS total_call_seconds,
11 round(sum(uad.total_call_seconds) / 60.0, 2) AS total_call_minutes,
12 sum(uad.total_sms_count) AS total_sms,
13 round(sum(uad.total_data_mb) / 1024.0, 2) AS total_data_used_gb,
14 sum(uad.total_charge_amount) AS total_usage_charges
15FROM customers c
16 JOIN accounts a ON a.customer_id = c.customer_id
17 JOIN subscriptions s ON s.account_id = a.account_id
18 JOIN plans p ON p.plan_id = s.plan_id
19 JOIN usage_aggregates_daily uad ON uad.subscription_id = s.subscription_id
20GROUP BY c.customer_id, c.first_name, c.last_name, c.company_name, a.account_number, s.subscription_number, p.plan_name;
21
22alter table public.v_customer_usage_360_summary
23 owner to postgres;