Check out example codes for "sql random sampling per group". It will help you in understanding the concepts better.

Code Example 1

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

Learn ReactJs, React Native from akashmittal.com