假设,值是1、2、3,也有可能是4、5、6,我要取出2来,或者5

解决方案 »

  1.   

    什么意思?具体给个例子
    where colname=2 or colname=5
    不就行了吗?
      

  2.   

    row_number() over(order by colx desc) rn
    ...)
    where rn=2
      

  3.   

    取出第二大的。假如这一列的列名为col1
    select * from tt a
    where exists(select 1 from tt where col1>a.col1)
      and exists(select 1 from tt where col1<a.col1)
    或者用分析函数
    select * from(
      select tt.*,dense_rank()over(order by col1 desc)dk)
    where dk=2
      

  4.   

    如果只有3条记录,可以用3楼的row_number
      

  5.   

    ....你自己题给得不详细,别人怎么给你写得详细
    而且这已经很详细了
    你可以将4楼的dense_rank换成row_number
    tt是表名