| | 118 | |
| | 119 | == Client Engagement & Conversion — Semi-Annual == |
| | 120 | |
| | 121 | What steps do clients go through over a six month period? |
| | 122 | This report segments the clients into two types - Cold interest meaning client only made an inquiry, |
| | 123 | and Warm interest meaning client made an appointment. Ranking them by an engagement score based on the inquiry volume and the appointment count. |
| | 124 | Showing the average price range for each client and the time taken from first inquiry to an appointment. |
| | 125 | With the goal for giving insight into the behaviour of clients. |
| | 126 | |
| | 127 | === SQL |
| | 128 | |
| | 129 | {{{ |
| | 130 | WITH client_inquiries AS ( |
| | 131 | SELECT |
| | 132 | c.client_id, |
| | 133 | c.name AS client_name, |
| | 134 | c.email AS client_email, |
| | 135 | c.phone AS client_phone, |
| | 136 | COUNT(DISTINCT i.inquiry_id) AS total_inquiries, |
| | 137 | MIN(i.created_at) AS first_inquiry_date, |
| | 138 | MAX(i.created_at) AS last_inquiry_date, |
| | 139 | ROUND(AVG(u.price), 2) AS avg_inquired_price |
| | 140 | FROM project.client c |
| | 141 | JOIN project.inquiry i ON c.client_id = i.client_id |
| | 142 | AND i.created_at >= CURRENT_DATE - INTERVAL '6 months' |
| | 143 | JOIN project.unit u ON i.unit_id = u.unit_id |
| | 144 | GROUP BY c.client_id, c.name, c.email, c.phone |
| | 145 | ), |
| | 146 | client_appointments AS ( |
| | 147 | SELECT |
| | 148 | c.client_id, |
| | 149 | COUNT(DISTINCT a.appointment_id) AS total_appointments, |
| | 150 | MIN(ts.date) AS first_appointment_date |
| | 151 | FROM project.client c |
| | 152 | JOIN project.appointment a ON c.client_id = a.client_id |
| | 153 | JOIN project.timeslot ts ON a.timeslot_id = ts.timeslot_id |
| | 154 | WHERE ts.date >= CURRENT_DATE - INTERVAL '6 months' |
| | 155 | GROUP BY c.client_id |
| | 156 | ) |
| | 157 | |
| | 158 | SELECT |
| | 159 | RANK() OVER ( |
| | 160 | ORDER BY ( |
| | 161 | ci.total_inquiries + |
| | 162 | COALESCE(ca.total_appointments, 0) * 3 |
| | 163 | ) DESC |
| | 164 | ) AS engagement_rank, |
| | 165 | ci.client_name, |
| | 166 | ci.client_email, |
| | 167 | ci.client_phone, |
| | 168 | CASE |
| | 169 | WHEN COALESCE(ca.total_appointments, 0) > 0 THEN 'Warm Interest' |
| | 170 | ELSE 'Cold Interest' |
| | 171 | end AS interest, |
| | 172 | ci.total_inquiries, |
| | 173 | COALESCE(ca.total_appointments, 0) AS total_appointments, |
| | 174 | CASE |
| | 175 | WHEN ca.first_appointment_date IS NOT NULL |
| | 176 | THEN (ca.first_appointment_date - ci.first_inquiry_date::date) |
| | 177 | ELSE NULL |
| | 178 | end AS days_to_first_appointment, |
| | 179 | ci.avg_inquired_price, |
| | 180 | ci.first_inquiry_date, |
| | 181 | ci.last_inquiry_date |
| | 182 | FROM client_inquiries ci |
| | 183 | LEFT JOIN client_appointments ca ON ci.client_id = ca.client_id |
| | 184 | ORDER BY engagement_rank; |
| | 185 | }}} |