DatabaseCreation: Customer support ticket timeline.sql

File Customer support ticket timeline.sql, 1.7 KB (added by 231045, 2 weeks ago)
Line 
1create view public.v_customer_support_ticket_timeline
2 (customer_id, customer_name, email, account_number, subscription_number, plan_name, ticket_id, ticket_type,
3 subject, priority, ticket_status, ticket_created_at, ticket_closed_at, interaction_id, interaction_type,
4 channel, interaction_time, notes, old_status, new_status, employee_name)
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 t.ticket_id,
13 t.ticket_type,
14 t.subject,
15 t.priority,
16 t.status AS ticket_status,
17 t.created_at AS ticket_created_at,
18 t.closed_at AS ticket_closed_at,
19 ci.interaction_id,
20 ci.interaction_type,
21 ci.channel,
22 ci.interaction_time,
23 ci.notes,
24 ci.old_status,
25 ci.new_status,
26 (e.first_name || ' '::text) || e.last_name AS employee_name
27FROM customers c
28 JOIN crm_tickets t ON t.customer_id = c.customer_id
29 LEFT JOIN subscriptions s ON s.subscription_id = t.subscription_id
30 LEFT JOIN accounts a ON a.account_id = COALESCE(t.account_id, s.account_id)
31 LEFT JOIN plans p ON p.plan_id = s.plan_id
32 LEFT JOIN crm_interactions ci ON ci.ticket_id = t.ticket_id
33 LEFT JOIN employees e ON e.employee_id = ci.employee_id;
34
35alter table public.v_customer_support_ticket_timeline
36 owner to postgres;