Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- query = '''
- WITH counts_per_user AS (SELECT user_id,
- COUNT (counts) AS active_days
- FROM (SELECT user_id,
- count (id) AS posts_number,
- DATE_TRUNC('day', creation_date::date) AS day
- FROM stackoverflow.posts
- WHERE creation_date::date BETWEEN '2008-12-01' AND '2008-12-07'
- GROUP BY user_id, DATE_TRUNC('day', creation_date::date)
- ORDER BY day) AS counts
- GROUP BY user_id)
- SELECT SUM (active_days)::int AS total_counts,
- COUNT (DISTINCT user_id) AS sum_users
- FROM counts_per_user
- '''
- test = pd.read_sql_query(query, con=engine)
- test.head(10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement