0

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!

Piotr Findeisen
  • 19,480
  • 2
  • 52
  • 82

2 Answers2

0

i think you can try like this in sql server

SELECT TOP 50 column FROM table ORDER BY NEWID()

for more information you can visit this link

Xar Hang
  • 21
  • 10
0

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;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786