Tempo alla prima risposta di gruppo per i topic creati in un determinato periodo
Restituisce il tempo necessario affinché un membro di un gruppo specifico risponda per la prima volta a topic “normali” (non Messaggi Privati) creati da un utente che non fa parte del gruppo indicato. Il parametro :group_name della query è impostato su “staff” per impostazione predefinita. Con questo valore, fornirà il tempo alla prima risposta da parte dei membri dello staff. Puoi modificare il valore di questo parametro per ottenere i tempi di risposta per gruppi diversi, ad esempio “customer_support”.
Tieni presente che le date dovrebbero tecnicamente essere fornite nel formato yyyy-mm-dd, ma la query accetta anche date nel formato dd-mm-yyyy.
-- [params]
-- date :start_date
-- date :end_date
-- string :group_name = staff
WITH group_response_times AS (
SELECT
t.category_id,
t.id AS topic_id,
EXTRACT(EPOCH FROM (p.created_at - t.created_at)) / 60 AS response_time_minutes,
p.user_id AS staff_user_id,
ROW_NUMBER() OVER (PARTITION BY t.id ORDER BY p.created_at) AS row_num
FROM posts p
JOIN topics t ON t.id = p.topic_id
WHERE t.user_id NOT IN (SELECT user_id
FROM group_users gu JOIN groups g ON g.id = gu.group_id
WHERE gu.user_id > 0 AND g.name = :group_name)
AND p.user_id IN (SELECT user_id
FROM group_users gu JOIN groups g ON g.id = gu.group_id
WHERE gu.user_id > 0 AND g.name = :group_name)
AND t.archetype = 'regular'
AND t.deleted_at IS NULL
AND p.post_type = 1
AND p.deleted_at IS NULL
AND t.created_at BETWEEN :start_date AND :end_date
)
SELECT
category_id,
topic_id,
staff_user_id,
ROUND(response_time_minutes::numeric, 2) AS response_time_minutes
FROM group_response_times
WHERE row_num = 1
ORDER BY category_id, response_time_minutes
Tempo medio alla prima risposta di gruppo per categoria:
Utilizza la stessa logica della query precedente, ma restituisce il tempo medio alla prima risposta da parte dei membri del gruppo indicato per categoria, per i topic creati da utenti che non fanno parte del gruppo stesso nel periodo di tempo definito dai parametri :start_date e :end_date. Come nella query precedente, se il parametro :group_name viene lasciato al suo valore predefinito “staff”, restituirà i tempi medi di prima risposta dello staff per i topic normali creati da utenti non appartenenti allo staff.
-- [params]
-- date :start_date
-- date :end_date
-- string :group_name = staff
WITH group_response_times AS (
SELECT
t.category_id,
t.id AS topic_id,
EXTRACT(EPOCH FROM (p.created_at - t.created_at)) / 60 AS response_time_minutes,
p.user_id AS staff_user_id,
ROW_NUMBER() OVER (PARTITION BY t.id ORDER BY p.created_at) AS row_num
FROM posts p
JOIN topics t ON t.id = p.topic_id
WHERE t.user_id NOT IN (SELECT user_id
FROM group_users gu JOIN groups g ON g.id = gu.group_id
WHERE gu.user_id > 0 AND g.name = :group_name)
AND p.user_id IN (SELECT user_id
FROM group_users gu JOIN groups g ON g.id = gu.group_id
WHERE gu.user_id > 0 AND g.name = :group_name)
AND t.archetype = 'regular'
AND t.deleted_at IS NULL
AND p.post_type = 1
AND p.deleted_at IS NULL
AND t.created_at BETWEEN :start_date AND :end_date
)
SELECT
category_id,
ROUND(AVG (response_time_minutes)::numeric, 2) AS average_response_time_minutes,
COUNT(*) AS num_topics_with_staff_responses
FROM group_response_times
WHERE row_num = 1
GROUP BY category_id

