你这样是不行的,需要先排序再取rownum,否则rownum的值仍然是排序之前的select * from
       (select icp.item_id 
             from t_insured_change_product icp
             where 1=1
             and policy_id = 3964916 
             and change_id = 2471842 
             order by icp.item_id desc
       )
where rownum  =1

解决方案 »

  1.   

    给你一个网址:
    http://www.etake.com.cn/bbs1/printpage.asp?BoardID=5&ID=35
      

  2.   

    1、rownum是oracle系统顺序分配为从查询返回的行的编号,返回的第一行分配的是1,第二行是2,
      依此类推,这个伪字段可以用于限制查询返回的总行数。
    2、rownum不能以任何基表的名称作为前缀。
      

  3.   

    就是在返回的时候生成的rownum.
      

  4.   

    select * from
     (select ...
      order by ...       ) t
    where t.rownum  =1
      

  5.   

    这是销售部要求显示的三本卖得最好的书的查询语句。和你的要求有相似的地方
    select a.title,(a.retail-a.cost)/a.cost*100  as profit_rate ,rownum from(
    select isbn,title,(retail-cost)/cost*100 ,retail,cost,sum(quantity)
    from books  natural join  orderitems  
    group by isbn,title,(retail-cost)/cost*100,retail,cost  
    order by sum(quantity) desc) a
    where rownum<=3;
    看看
      

  6.   

    oracle 的各部分的解释顺序不一样。order by 总在rownum的后面duanzilin(寻)的为正解。