product_id user_id
223344 123
223344 234
223344 334
223344 222
225566 441
225566 443
225566 444
225566 445
取product_id对应的 3条不同的user_id的记录。
假如porduct_id没有对应的user_id ,则输出为空值.
223344 123
223344 234
223344 334
223344 222
225566 441
225566 443
225566 444
225566 445
取product_id对应的 3条不同的user_id的记录。
假如porduct_id没有对应的user_id ,则输出为空值.
解决方案 »
- Oracle中begin end问题
- 简述Oracle口令文件的作用,如何创建和使用口令文件
- ORACLE 9, WINDOWS,JOB任务问题.
- 在Long类型字段中存储大文本,出现性能的问题???
- 求一句SQL!
- oracle中sysdba用户通过odbc数据源连接,怎样配置?
- proc怎么调用存储过程?
- 我用SYSTEM登录DBA,启动数据库失败,请问怎么办在线等待!!!!
- ^_^^_^关于存储过程和job的问题,高手帮忙看看^_^^_^^_^^_^(分不多了!)
- 如何统计三张表的数据量
- oracle drop table 中间被终止会删除表中的数据吗...
- 从执行的性能上来讲,请问全局索引与分区索引各适合于什么场景?
select t.*, row_number() over (partition by product_id order by user_id) rn from t
) where rn <= 3;
with t as(
select 223344 product_id,123 user_id from dual union all
select 223344,234 from dual union all
select 223344,334 from dual union all
select 223344,222 from dual union all
select 225566,441 from dual union all
select 225566,443 from dual union all
select 225566,443 from dual union all
select 225566,445 from dual union all
select 225567,446 from dual union all
select 225568,447 from dual union all
select 225569,448 from dual
)
select t4.product_id,t3.user_id from
(select t1.product_id,t1.user_id,num2 from
(select t.product_id,t.user_id,row_number() over(partition by product_id,user_id order by user_id) num1,
dense_rank() over(partition by product_id order by user_id) num2 from t)t1
where t1.num1 = 1 and t1.num2 <= 3)t3,
(select distinct product_id,level num2 from t connect by level <=3)t4
where t3.product_id(+) = t4.product_id and t3.num2(+) = t4.num23 223344 234
2 223344 222
1 223344 123
6 225566 445
5 225566 443
4 225566 441
13 225567
15 225567
7 225567 446
14 225568
11 225568
8 225568 447
9 225569 448
12 225569
10 225569 取product_id对应的 3条不同的user_id的记录。
假如porduct_id没有对应的user_id ,则输出为空值.
目的是先以每个product_id 为分组,在后面增加序列号。
然后再依据序列号进行选择就行了。