# Posts created for period

**URL:** https://meta.discourse.org/t/posts-created-for-period/275138
**Category:** Data & reporting
**Tags:** sql-query
**Created:** [September 14, 2016, 9:54pm UTC](https://meta.discourse.org/t/posts-created-for-period/275138 "2016-09-14T21:54:25Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![HAWK](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hawk/32/86627_2.png) [@HAWK](https://meta.discourse.org/u/HAWK)
#### Post date: [September 14, 2016, 9:54pm UTC](https://meta.discourse.org/t/posts-created-for-period/275138/1 "2016-09-14T21:54:25Z")

</div>

### Posts created for period

Got what I need (thanks @meglio) so updating this for future posterity.

```
-- [params]
-- date :date_from
-- date :date_to
-- int :min_posts = 1

WITH user_activity AS (
    SELECT p.user_id, count (p.id) as posts_count
    FROM posts p
    LEFT JOIN topics t ON t.id = p.topic_id
    WHERE p.created_at::date BETWEEN :date_from::date AND :date_to::date
        AND t.deleted_at IS NULL
        AND t.visible = TRUE
        AND t.closed = FALSE
        AND t.archived = FALSE
        AND t.archetype = 'regular'
        AND p.deleted_at IS NULL
        
    GROUP BY p.user_id
)
SELECT COUNT(user_id)
FROM user_activity
WHERE posts_count >= :min_posts

```
