I need to pull 'n' number of records from each group randomly from a table. I have tried using rownum() over(partition by.....) but I not able to pull out per group. distinct on id wouldn't work because I need more than one record per group. consider the following table:
ST ID
MA 1
CA 2
IL 3
ME 4
MA 5
MA 6
MA 7
IL 8
ME 9
CA 10
CA 11
CA 12
ME 13
ME 14
IL 15
IL 16
IL 17
My o/p should look something like this: when n=2
MA 1
CA 2
IL 3
ME 4
MA 5
CA 10
IL 16
ME 13