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