I want to pull data to anayze user behaviour transaction. I just need to randomly select 50 user for each dates with their transaction record. Does anyone know how can I do this?
Thanks in advance!
I want to pull data to anayze user behaviour transaction. I just need to randomly select 50 user for each dates with their transaction record. Does anyone know how can I do this?
Thanks in advance!
Assuming you have one row per user, then you can use:
select t.*
from t
order by random()
limit 50;
If you have multiple rows per user and want the complete data for 50 of them, then you can use join
:
select t.*
from t join
(select distinct user_id
from t
order by random()
limit 50
) u50
on t.user_id = u50.user_id;