having rownum<=10
-->这是什么语发,不通,重写.

解决方案 »

  1.   

    insert into cdz_dqtstjb(DIQUNAME,bno,bname,price,amount,mayang)
       (select d.DIQUNAME,substr(b.bno,1,6) as bno,b.bname,b.price,
      sum(b.amount) as amount,sum(b.mayang) as mayang
       from sales a,sales_mx b,units c,diqus d
       where a.sno=b.sno and a.uno=c.uno and c.diqu=d.diqu
     and xsbz='1'
             and to_char(a.sale_date,'yyyy-mm-dd')>='2003-03-01'
             and to_char(a.sale_date,'yyyy-mm-dd')<='2003-03-31'
       group by d.DIQUNAME,substr(b.bno,1,6),b.bname,b.price
       order by d.DIQUNAME desc,substr(b.bno,1,6) desc,b.bname desc,b.price desc) tab
       where tab.nownum<=10
      

  2.   

    sorry,to_be is:insert into cdz_dqtstjb(DIQUNAME,bno,bname,price,amount,mayang)
       select tab.zz,tab.bno,tab.yy,tab.xx,tab.amount,tab.mayang from  
       (select d.DIQUNAME zz,substr(b.bno,1,6) bno,b.bname yy,b.price xx,
      sum(b.amount) amount,sum(b.mayang)  mayang
       from sales a,sales_mx b,units c,diqus d
       where a.sno=b.sno and a.uno=c.uno and c.diqu=d.diqu
     and xsbz='1'
             and to_char(a.sale_date,'yyyy-mm-dd')>='2003-03-01'
             and to_char(a.sale_date,'yyyy-mm-dd')<='2003-03-31'
       group by d.DIQUNAME,substr(b.bno,1,6),b.bname,b.price
       order by d.DIQUNAME desc,substr(b.bno,1,6) desc,b.bname desc,
    b.price desc) tab
       where tab.nownum<=10
      

  3.   

    语句本身已有不通之处,怎么可能对如此多分组呢,若出现在重复,怎可能取不同DIQUNAME的前十呢?
      

  4.   

    哪里这么复杂,用oracle的分析函数,很简单的,8i以上支持,自己查吧
      

  5.   

    有一小错:
    where tab.nownum<=10改为:
    where rownum<=10。
      

  6.   

    感谢:BlueskyWide(谈趣者)
    程序运行没错,但有一个问题,只取了10条纪录,而不是每个地区取10条纪录。
      

  7.   

    简单点吧:
    insert into cdz_dqtstjb(DIQUNAME,bno,bname,price,amount,mayang)
       select tab.zz,tab.bno,tab.yy,tab.xx,tab.amount,tab.mayang from  
       (select d.DIQUNAME zz,substr(b.bno,1,6) bno,b.bname yy,b.price xx,
      sum(b.amount) amount,sum(b.mayang)  mayang
       from sales a,sales_mx b,units c,diqus d
       where a.sno=b.sno and a.uno=c.uno and c.diqu=d.diqu
     and xsbz='1'
             and to_char(a.sale_date,'yyyy-mm-dd')>='2003-03-01'
             and to_char(a.sale_date,'yyyy-mm-dd')<='2003-03-31'
     and d.DIQUNAME='丰台区'
          order by d.DIQUNAME desc,substr(b.bno,1,6) desc,b.bname desc,b.price desc) tab
       where nownum<=10把'丰台区'改为你知道的区,有几个区就执行几次吧。