select identity(int,1,1) as xh,* into #a from tb 
delete #a from #a a,
(select xh,max(a) as a from #a) b 
where a.xh=b.xhselect max(a) from #a

解决方案 »

  1.   

    select max(a) from tb1 where a < ( select max(a) from tb1 )
      

  2.   

    select top 1 * from tablename where col not in (select Max(col) from tablename) order by col desc
      

  3.   

    select top 1 a.* from
     (select top 2 * from table
      order by ID desc) as a
    order by a.ID
      

  4.   

    select a from 表 a
    where(select count(*) from 表 where a>=a.a)=2  --第二大
    select a from 表 a
    where(select count(*) from 表 where a>=a.a)=3  --第三大select a from 表 a
    where(select count(*) from 表 where a>=a.a)=n  --第N大
      

  5.   

    邹建的方法在大数据量的表中查询速度太慢(无法忍受),我献一条(在100多万条的收费表中速度不超过1秒)select min(a) from (select  distinct top n a from 表 order by a desc) t
    (第n大的)
      

  6.   

    select max(a) as a from table where a < ( select max(a) from table )
      

  7.   

    to : sanmaotuo(老冯)烦请在你的100多万条的收费表中测试一下楼上 sankis() 的方法,看看效率如何?
      

  8.   

    如果有重復的就這樣:select a from 表 a
    where(select count(Distinct a) from 表 where a>=a.a)=n  --第N大不過卻很慢
    不知可以怎樣優化?
      

  9.   

    你们在写top的时候考虑了有a的数值是一样的纪录了吗??????不用写with tie???
      

  10.   

    TO :jackxing(Jack) 测试了。速度很快。可惜SANKIS()的语句只能计算第2大的,不通用
      

  11.   

    to: woshishui11121113(我是谁)
    老冯写的已经DISTINCT了。
      

  12.   

    to : sanmaotuo(老冯)没错,还是你的方法更高一筹,谢了!
    真羡慕你,有100多万条数据可用,呵呵
      

  13.   

    to : sanmaotuo(老冯)没错,还是你的方法更高一筹,谢了!
    真羡慕你,有100多万条数据可用,呵呵