select * from ATABLE_no a
where (select count(1) from ATABLE_no where N_CON<=a.N_CON)
between 2 and 3

解决方案 »

  1.   

    if object_id('[ATABLE_no]') is not null drop table [ATABLE_no] 
     go 
    create table [ATABLE_no]([N_FNAME] varchar(10),[N_CON] int)
    insert [ATABLE_no] select 'AF',1
    union all select 'BF',10
    union all select 'CF',20
    union all select 'ANF',60
    goselect *
    from [ATABLE_no] t
    where (
        select count(1) 
        from [ATABLE_no]
        where N_CON<=t.N_CON
        ) between 2 and 3
    /*
    N_FNAME    N_CON
    ---------- -----------
    BF         10
    CF         20(2 行受影响)
    */
      

  2.   

    测试数据:create table ATABLE_no(N_FNAME nvarchar(20),N_CON int)
    insert ATABLE_no select 'AF',1
    union all select 'BF',10
    union all select 'CF',20
    union all select 'ANF',60
    union all select 'BF',5
    2.pt1314917 的语句:select * from ATABLE_no a
    where (select count(1) from ATABLE_no where N_CON<=a.N_CON)
    between 2 and 3/*
    --结果:
    N_FNAME    N_CON
    -----------------
    BF 10
    BF 5*/
      

  3.   

    当N_FNAME 字段有重得值时,得不到正确的结果,htl258 的语句也一样.
      

  4.   

    哦,你是要第二大或者第三大的?
    那就改成>=
    select * from ATABLE_no a
    where (select count(1) from ATABLE_no where N_CON>=a.N_CON)
    between 2 and 3
      

  5.   

    如果有重复的,就这样。
    select * from ATABLE_no a
    where (select count(distinct N_CON) from ATABLE_no where N_CON>=a.N_CON)
    between 2 and 3