日期:2014-05-17 浏览次数:20797 次
SELECT col1,text1 FROM (SELECT t.*, row_number() over(PARTITION BY text1 ORDER BY col1) rn FROM t) WHERE rn <= 3
------解决方案--------------------
select * from tab
group by text1
having count(text1)<=3
union
select * from tab
group by text1
having count(text1)>3
where rownum<=3
------解决方案--------------------
select col1,text1 from (select col1,text1,row_number() over(partition by text1 order by col1) rn from tb) a where rn<=3
------解决方案--------------------
Ding
------解决方案--------------------
引用:
SQL code
SELECT col1,text1
FROM (SELECT t.*, row_number() over(PARTITION BY text1 ORDER BY col1) rn FROM t)
WHERE rn <= 3
------解决方案--------------------
select * from
(
select col1,text1,row_number()over(partition by text1 order by col1) as num from tb
)
where num<=3
------解决方案--------------------
select * from TABNAME t where (select count(1) from TABNAME where text1 = t.text1 and col1 < t.col1 and rownum <= 3) < 3