create table music(
music_id int primary key,
userid int
);
insert into music(music_id)
select rownum rn from dual connect by level<1000;
update music set userid= mod(music_id,5);
commit;
要求:
每个作者随机抽取他的3个作品。
SQL如下
select * from
(
select music_id,userid,ROW_NUMBER() OVER (PARTITION BY userid ORDER BY dbms_random.random()) rn from music
)
where rn<=3;
第一次执行:
第二次执行:
这个方法只针对Oracle有效(使用了它的分析函数)