Sì, puoi usare la seguente query per questo:
--[params]
-- date :start_date
-- date :end_date
-- null category_id :category_id
-- null user_id :user_id
-- boolean :include_subcategories = false
SELECT
u.username AS "Utente",
p.created_at::date AS "Data",
COUNT(p.id) AS "Conteggio"
FROM posts p
INNER JOIN topics t ON t.id = p.topic_id AND t.deleted_at IS NULL
INNER JOIN users u ON p.user_id = u.id
LEFT JOIN categories c ON t.category_id = c.id
WHERE p.created_at::date BETWEEN :start_date AND :end_date
AND p.deleted_at IS NULL
AND t.archetype = 'regular'
AND p.post_type = 1
AND (
:category_id IS NULL
OR t.category_id = :category_id
OR (:include_subcategories AND c.parent_category_id = :category_id)
)
AND (:user_id IS NULL OR p.user_id = :user_id)
GROUP BY u.username, p.created_at::date
ORDER BY p.created_at::date ASC, u.username
Parametri:
- :start_date & :end_date: Definiscono l’intervallo di tempo del report (richiesto)
- :category_id: Filtro opzionale per una categoria specifica
- :user_id: Filtro opzionale per un utente specifico
- :include_subcategories: Opzione per includere le sottocategorie della categoria scelta
Questa query mostra:
- Utente: Nome utente dell’autore del post
- Data: La data di calendario in cui sono stati creati i post
- Conteggio: Numero di post creati da quell’utente in quella data
Dati di esempio:
| Utente | Data | Conteggio |
|---|---|---|
| utente 1 | 2023-01-01 | 3 |
| utente 2 | 2023-01-01 | 2 |
| utente 3 | 2023-01-01 | 1 |
| utente 1 | 2023-01-02 | 2 |
| utente 2 | 2023-01-02 | 3 |
| utente 1 | 2023-01-03 | 1 |
| … | … | … |