Search
 
SCRIPT & CODE EXAMPLE
 

SQL

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
Comment

PREVIOUS NEXT
Code Example
Sql :: apex select list ORA-20999 
Sql :: mysql disable foreign keys check 
Sql :: convert int to varchar sql 
Sql :: postgresql get last day of month 
Sql :: sql server pagination 
Sql :: check mysql version phpmyadmin 
Sql :: oracle db create new schema 
Sql :: select * from table where name like 
Sql :: tsql rename table 
Sql :: prosys sql log 
Sql :: convert uniqueidentifier to varchar in sql 
Sql :: how to install mysql server on centos 7 
Sql :: mysql mediumint max value 
Sql :: mysql delete all where id is not equal 
Sql :: group concat with separator 
Sql :: oracle list service names 
Sql :: mysql reset auto increment to 1 
Sql :: oracle character set 
Sql :: Configure MYSQL to run on another port number, other than the default port 3306 ubuntu linux 
Sql :: create column sql server 
Sql :: how to add default constraint in mysql 
Sql :: list foreign data tables postgres psql 
Sql :: access mysql command mac xampp 
Sql :: sql server convert string to date 
Sql :: backup postgres database 
Sql :: how to use like in sql 
Sql :: oracle db get table sizes 
Sql :: MySQL FIND_IN_SET() 
Sql :: t sql get foreign key 
Sql :: nosql databases list 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =