各位高手 
我用的是ORACLE 8i 客户端数据库 现在我想查询每个科别按业绩排序后取前100名的语句,
  表 ITEMS A,PK_ITEMS B
   Select *  from 
        (select a.section_no 科别,
                a.items_no 货号,
               a.name 品名,
               sum(b.qty)销售数量,
               sum(b.amount) 业绩 
            from items a,PK_ITEMS b
           where a.items_no=b.items_no
                 and b.work_date>=to_date('yyyymmdd','20091201')
                 and b.work_date<=to_date('yyyymmdd','20091201')
               group by a.section_no ,a.items_no 
              order by sum(b.amount) desc
             )
       where rownum <=100 在ORACLE中执行报错missing right parenthesis 
  请问怎么解决

解决方案 »

  1.   

    select a.section_no 科别, 
                    a.items_no 货号, 
                  a.name 品名, 
                  sum(b.qty)销售数量, 
                  sum(b.amount) 业绩 
                from items a,PK_ITEMS b 
              where a.items_no=b.items_no 
                    and b.work_date>=to_date('yyyymmdd','20091201') 
                    and b.work_date <=to_date('yyyymmdd','20091201') 
                  group by a.section_no ,a.items_no 
                  order by sum(b.amount) desc 你的内层sql就错了,select 中出现的非聚合字段都应该出现在group by里面,掉了name
      

  2.   

      Select *  from
            (select a.section_no 科别,
                    a.items_no 货号,
                  a.name 品名,
                  sum(b.qty)销售数量,
                  sum(b.amount) 业绩
                from items a,PK_ITEMS b
              where a.items_no=b.items_no
                    and b.work_date>=to_date('yyyymmdd','20091201')
                    and b.work_date <=to_date('yyyymmdd','20091201')
                  group by a.section_no ,a.items_no,a.name
                  order by sum(b.amount) desc
                )
          where rownum <=100 
      

  3.   

      Select *  from
            (select a.section_no 科别,
                    a.items_no 货号,
                  a.name 品名,
                  sum(b.qty)销售数量,
                  sum(b.amount) 业绩
                from items a,PK_ITEMS b
              where a.items_no=b.items_no
                    and b.work_date>=to_date('yyyymmdd','20091201')
                    and b.work_date <=to_date('yyyymmdd','20091231')
                  group by a.section_no ,a.items_no,a.name
                  order by 业绩 desc
                )
          where rownum <=100 ;
      

  4.   

    select * from 
    (
    select a.section_no 科别, 
                    a.item_no 货号, 
                  a.name 品名, 
                  sum(b.qty)销售数量, 
                  sum(b.amount) 业绩 
                from items a,PK_ITEMS b 
              where a.item_no=b.item_no 
                    and a.section_no=30
                    and b.work_date>=to_date('20091201','yyyymmdd') 
                    and b.work_date <=to_date('20091227','yyyymmdd') 
                  group by a.section_no ,a.item_no ,a.name
                  order by  5 desc 
                  )
                  where rownum<=100
    我这样写的 但还是提示 :在ORACLE中执行报错missing right parenthesis 我的意思是我查询到的数据按业绩排序之后在取前100名,哪位高手能给个例子让我看看那。