如题,我想取得distinct之后的指定行记录,请大侠指教.

解决方案 »

  1.   

     select distinct(列A) from table where rownum<=2
    这样子不行  它优先执行ROWNUM 达不到我要的效果
    列A
    1
    1
    2
    2
    3
    3
    上面的sql执行结果是1
    我想要的执行结果是
    1
    2
      

  2.   

    嵌套
    select * from(
      select distinct 列A from table)
    where rownum<=2
      

  3.   

    子查询:
    select * from (select distinct(列a) from table) where rownum<=2
      

  4.   

    突然就发现ORACLE不能理解啊
    Select a From (Select Distinct a From table1) Where Rownum<=2;
    结果
    1
    2
    Select a From (Select Distinct a From table1) Where Rownum=0;
    结果

    Select a From (Select Distinct a From table1) Where Rownum=1;
    结果1Select a From (Select Distinct a From table1) Where Rownum=2;
    结果

    有没有人能给我解释一下啊、?
      

  5.   

    rownum是赋给结果集的伪列
    如果rownum=0则当然没有记录了
    如果条件为rownum=2,没有rownum=1的记录,就不会有rownum=2,所以结果为空
    可以用
    select *
    from(
      select t.*,rownum as rn
      from t
      where rownum<=2)
    where rn=2
      

  6.   

    select * from(
      select distinct  列 from 表)
    where rownum=指定行数
      

  7.   

    谢了,问题已用程序代码解决.才接触ORACLE不知道是这样的!