Answers for "sql random sampling per group"

SQL
1

sql random sampling per group

with randomly_sorted_users as (

    select
        user_id,
        signup_date,
        row_number() over(partition by date_trunc('year', signup_date)
                            order by random()) as random_sort
    from
        user_table

)
select
    user_id,
    signup_date
from
    randomly_sorted_users
where
    random_sort <= 5
Posted by: Guest on July-17-2020

Code answers related to "sql random sampling per group"

Code answers related to "SQL"

Browse Popular Code Answers by Language