plsql查询:
con_id,prod_id
1 2001
1 2002
1 2003
1 2004
2 2005
2 2006
2 2007
2 2008
.
.
.
要求是每个con_id 取出任意N个prod_id(已3为例)
要求结果如下:
con_id,prod_id
1 2001
1 2002
1 2003
2 2005
2 2006
2 2007
------解决方法--------------------------------------------------------
使用分析函数应该行的:
SELECT * FROM
(
SELECT con_id,prod_id,ROW_NUMBER() OVER (PARTITION BY con_id ORDER BY prod_id) rn FROM table1
) a
where a.rn <4