sql random sampling per group

Solutions on MaxInterview for sql random sampling per group by the best coders in the world

showing results for - "sql random sampling per group"
Francesca
24 May 2020
1with randomly_sorted_users as (
2
3    select
4        user_id,
5        signup_date,
6        row_number() over(partition by date_trunc('year', signup_date)
7                            order by random()) as random_sort
8    from
9        user_table
10
11)
12select
13    user_id,
14    signup_date
15from
16    randomly_sorted_users
17where
18    random_sort <= 5