Statistiche ora per ora

La query sottostante mostrerà i post creati per ogni ora del giorno.

-- [params]
-- int :months_ago = 1

WITH query_period AS
(SELECT date_trunc('month', CURRENT_DATE) - INTERVAL ':months_ago months' AS period_start,
                                                    date_trunc('month', CURRENT_DATE) - INTERVAL ':months_ago months' + INTERVAL '1 month' - INTERVAL '1 second' AS period_end)
SELECT EXTRACT (HOUR FROM p.created_at) AS hour,
  COUNT(p.id) AS amount
FROM posts p
JOIN topics t ON t.id = p.topic_id
JOIN query_period qp ON p.created_at >= qp.period_start
AND p.created_at <= qp.period_end
WHERE t.archetype = 'regular'
AND p.user_id > 0
GROUP BY hour
ORDER BY hour

Il plugin Data Explorer è uno dei plugin che installiamo per impostazione predefinita. È sufficiente attivarlo in Admin - Plugin. Se hai domande specifiche relative alla nostra hosting, inviale a support@discoursehosting.com.