top_vlad

Untitled

Nov 7th, 2024
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. with x  as   (select user_id,
  2.            created_at::date date,
  3.     count(id) as txs
  4.         from transactions t
  5.     where  --user_id = 17419 and
  6.       type like '%sell_subscription%'
  7.       and created_at::date in ('2024-11-01','2024-10-01')
  8.     group by 1,2
  9.     order by 2,1)
  10.  
  11.     select x.user_id,
  12.            concat(u.first_name, ' ', u.last_name) as user_name,
  13.            MAX(txs)filter (where date = '2024-10-01') as _2024_10_01,
  14.            MAX(txs)filter (where date = '2024-11-01') as _2024_11_01
  15.         from x
  16.         join users u on x.user_id = u.id
  17. group by 1,2
  18. having MAX(txs)filter (where date = '2024-10-01') > 50
  19. order by 3 desc
Advertisement
Add Comment
Please, Sign In to add comment