比如表TableA有三个字段:C1 C2 C3现在按C3排序查询:select * from TableA order by C3 desc
只取其中一条则:select * from (select * from TableA order by C3 desc) where rownum=1;
能返回按C3字段排序后的第一行。但是如果不使用子查询的方式,是否可能实现同样的效果?

解决方案 »

  1.   


    select a.* from TableA a not exists (select 1 from TableA b where a.C3<b.C3)
      

  2.   

    --试试:
    select a.* from TableA a  where not exists (select 1 from TableA b where a.C3<b.C3)
      

  3.   

    应该要有两次SELECT才可以达到这个要求吧
      

  4.   

    大概思路。使用RANK函数,应该可以不用子查询。SELECT C1, C2, C3 RANK() OVER(ORDER BY C3 DESC) FROM TABLEA
      

  5.   


    --估计不行
    SELECT B.SID1,B.NAME,  
                 ROW_NUMBER() OVER(ORDER BY B.SID1 desc)
                 FROM yyq B  
                 WHERE rownum = 1
      

  6.   

    楼主的语句,是嵌套吧,应该不是严格意义上的子查询吧
    姑且把这种也算子查询,那么,楼主的意思是想一条语句搞定
    非常遗憾的说一下,无法满足要求,因为使用rank函数,也需要外层过滤的select * from 
    (
        select c1,c2,c3
               ,row_number() over(order by QUERY_TAB_FIELD) rank_order
            from TABLE_A t
        )
     where rank_order = 1
      

  7.   

    select 
    max(c1) keep(dense_rank last order by c3) as c1,
    max(c2) keep(dense_rank last order by c3) as c2,
    max(c3) keep(dense_rank last order by c3) as c3
    from TABLEA
      

  8.   

    补充说明,该办法只查出字段C3记录中最大的一条记录
    比如 c1 c2 c3
         1  3  1
         3  4  2
    则查询的结果是 3 4 2
      

  9.   


    select * from table  where  c3=MAX(C3)
      

  10.   


    --不用子查询 是不可能的 select * from TableA where c3=(select max(c3) from tablea)--或者分析函数