表tab1,字段a,t
运行:
select a,count(*) as b from tab1 group by a
结果:
a b
ww 510
qq 222
tt 111
---------
我要实现这样的功能:取出a列为ww,qq,tt....的10个t字段的内容,怎么实现?即每种10个。
表tab1,字段a,t
运行:
select a,count(*) as b from tab1 group by a
结果:
a b
ww 510
qq 222
tt 111
---------
我要实现这样的功能:取出a列为ww,qq,tt....的10个t字段的内容,怎么实现?即每种10个。
我来给你答案
select id=identity(int,1,1),a,t into ##tb from tb1
select * from ##tb,(select a,Min(id) as tag from ##tb group by a) tb where ##tb.id<tag+10 and ##tb.id>=tag
oracle:
select tab2.t,tab2.a from (select distinct a,t,dense_rank() over(partition by a order by t) tt from tab1) tab2 where tab2.tt<=10;
select top10 a,count(*) as b from tab1 where a='ww' group by a union all
select top10 a,count(*) as b from tab1 where a='qq' group by a union all
select top10 a,count(*) as b from tab1 where a='tt' group by a union all
...