# sql 查询每个gcid的前3个

0
[已解决问题] 解决于 2013-08-06 13:31
 gid gcname gcid 1 10元话费 2 2 10元话费 2 3 10元话费 2 4 10元话费 2 5 10元话费 2 6 10元话费 2 7 10元话费 2 8 20元话费 3 9 20元话费 3 10 20元话费 3 11 20元话费 3 12 20元话费 3 13 20元话费 3 14 20元话费 3 15 50元话费 4 16 50元话费 4 17 50元话费 4 18 50元话费 4 19 50元话费 4

0

select * from(
select gcid,name, row_number() over (partition by gcid
order by name desc) as rowno
from tel) A
where a.rowno<=3

kylin.chen | 小虾三级 |园豆：983 | 2013-07-16 18:30

kylin.chen | 园豆：983 (小虾三级) | 2013-07-16 18:31

0
```select * from table a
where 2>(select count(id) from table  b where a.gid<b.gid and a.gcid=b.gcid)```
Macbeth | 园豆：126 (初学一级) | 2013-07-17 09:20

0

select * from (select gid,gcname,gcid,case when row_number() over(partition by gcid order by gcid asc) = 1 then 1
when row_number() over(partition by gcid order by gcid asc) = 2 then 2
when row_number() over(partition by gcid order by gcid asc) = 3 then 3
else 4 end as rnt
from tableA) as t
where t.rnt <= 3

Eddiew | 园豆：286 (菜鸟二级) | 2013-07-17 10:00

您需要登录以后才能回答，未注册用户请先注册