如:
select f1,f2,f2 from t1 group by f1,f2,f3但我想对f1=1的记录条数限制为10条,=2的限制为10条。只要是f1不同的,就限制为10条 

解决方案 »

  1.   

    设你的表中有标识列为id(或者值不重复,可以比较大小的列),你限制的10条是取id最大的10条select f1,f2,f3 from t1 a where 10>(select count(1) from t1 b where b.id>a.id and a.f1=b.f1)如果你的表中没有这样的列,那只有借助临时表,用identity生成标识列,再这样做。
      

  2.   

    如果是取id最小的10条,则将
    where b.id>a.id and a.f1=b.f1改为
    where b.id<a.id and a.f1=b.f1
      

  3.   

    select f1,f2,f2 from tablename t1 
    where checksum(*) in (select top 10 checksum(*) from tablename where f1 = t1.f1)
    group by f1,f2,f3