Advertisement
AnnaCh1971

Задача 6 в проекте итоговые суммы

Jun 7th, 2023
715
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.62 KB | None | 0 0
  1. query = '''
  2. WITH counts_per_user AS (SELECT user_id,
  3.       COUNT (counts) AS active_days
  4. FROM (SELECT user_id,
  5.             count (id) AS posts_number,
  6.              DATE_TRUNC('day', creation_date::date) AS day
  7.       FROM stackoverflow.posts
  8.       WHERE creation_date::date BETWEEN '2008-12-01' AND '2008-12-07'
  9.       GROUP BY user_id, DATE_TRUNC('day', creation_date::date)
  10.       ORDER BY day) AS counts
  11.       GROUP BY user_id)
  12. SELECT SUM (active_days)::int AS total_counts,
  13.       COUNT (DISTINCT user_id) AS sum_users
  14. FROM  counts_per_user  
  15. '''
  16.  
  17. test =  pd.read_sql_query(query, con=engine)
  18. test.head(10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement