select guid,f001 from tablename a where guid in(select top 5 from tablename where f001=a.f001)
order by f001

解决方案 »

  1.   

    --上面写错了,改一下:select guid,f001 from tablename a 
    where guid in(select top 5 guid from tablename where f001=a.f001 order by f001)
      

  2.   

    select * from tablename t where guid in ( select top 5 guid from tablename t1 where t1.f001=t.f001)
      

  3.   

    --下面是测试
    declare @tablename table(guid varchar(20),f001 varchar(10))
    insert into @tablename
    select '000020090','001001'
    union all select '0000201#m','001001'
    union all select '000029oho','001001'
    union all select '00002ik5e','001001'
    union all select '00002llwc','001001'
    union all select '00002o0b6','001001'
    union all select '00002pxh1','001001'
    union all select '00002q7l9','001001'
    union all select '00002q8f1','001001'
    union all select '00002q9w4','001001'
    union all select '00002qbgp','001001'
    union all select '00002qp91','001002'
    union all select '00002qs60','001002'
    union all select '00002qnpo','001002'
    union all select '00002qn50','001002'
    union all select '00002qjxb','001002'
    union all select '00002qi6e','001002'
    union all select '00002qfzh','001002'
    union all select '00002qenb','001002'
    union all select '00002006r','001003'
    union all select '00002006.','001003'
    union all select '00002006+','001003'
    union all select '000020064','001003'
    union all select '0000200f*','001003'
    union all select '0000200g"','001003'
    union all select '00002qp3u','001008'
    union all select '00002qnjt','001008'
    union all select '00002qjod','001008'
    union all select '00002qi1r','001008'--查询
    select guid,f001 from @tablename a 
    where guid in(select top 5 guid from @tablename where f001=a.f001 order by f001)/*--测试结果
    guid                 f001       
    -------------------- ---------- 
    000020090            001001
    0000201#m            001001
    000029oho            001001
    00002ik5e            001001
    00002llwc            001001
    00002qp91            001002
    00002qs60            001002
    00002qnpo            001002
    00002qn50            001002
    00002qjxb            001002
    00002006r            001003
    00002006.            001003
    00002006+            001003
    000020064            001003
    0000200f*            001003
    00002qp3u            001008
    00002qnjt            001008
    00002qjod            001008
    00002qi1r            001008(所影响的行数为 19 行)
    --*/
      

  4.   

    select guid,f001 from tablename a 
    where guid in(select top 5 guid from tablename where f001=a.f001 order by f001)