多个联接引发错误,查询运行很长时间

时间:2017-11-21 10:11:20

标签: sql oracle oracle9i

我试图从多个表中提取数据,但由于数十亿的数据,我按年和月提取数据。查询运行很长时间并抛出空间错误。临时空间增加到最大尺寸仍然是错误抛出。

查询如下:

select DISTINCT 'NEW_TEST' as DIL
      ,(nvl(to_char(erg.rdrgrp_id), 'MASTER')) as PIN_ID
      ,ws.wrks_id as time_code
      ,ws.emp_id as NEW1
      ,(select emp_name
          from employee
         where emp_id = ws.emp_id) as employee_number
      ,wd.tcode_id as pay_code_id
      ,ws.wrks_tcode_sum as timesheet_entry_type
      ,wd.tcode_id as time_code
      ,wd.htype_name as hour_type
      ,(select htype_desc
          from hour_type
         where htype_name = wd.htype_name) as hour_type_desc
      ,null as hour_type_detail
      ,(wd.wrkd_minutes / 60) as timesheet_hours
      ,wd.tcode_id as pay_code_id
      ,ws.paygrp_id as pay_group_code
      ,(select paygrp_name
          from pay_group
         where paygrp_id = ws.paygrp_id) as pay_group_name
      ,ws.wrks_rules_applied as work_rule_desc
      ,wd.wrkd_overridden as time_entry_source_adjusted
      ,ws.shft_id as work_shift_id
      ,(select shft_name
          from shift
         where shft_id = ws.shft_id) as work_shift
      ,wd.job_id as job_code
      ,(select job_desc
          from job
         where job_id = wd.job_id) as job_desc
      ,wd.client_id as client
      ,wd.wrkd_rate as rate
      ,(select paygrptyp_name
          from view_pay_group
         where paygrp_id = ws.paygrp_id) as rate_uom
      ,(wd.wrkd_rate * wd.wrkd_minutes) / 60 as wage
      ,(select sum(wd.wrkd_minutes / 60 * wd.wrkd_rate)
          from work_detail wd
         where wd.wrks_id = ws.wrks_id) as amount
      ,wd.proj_id as project_number
      ,wd.proj_name as project_name
  from work_summary          ws
      ,employee_reader_group erg
      ,view_work_detail      wd
      ,employee_schedule     es
 where ws.emp_id = erg.emp_id
   and ws.wrks_id = wd.wrks_id
   and Ws.emp_id = es.emp_id
   and ws.wrks_work_date between ('01-JAN-2016') and ('31-MAR-2016');

1 个答案:

答案 0 :(得分:0)

ES表未加入任何内容

AND ES.EMP_ID   =ES.EMP_ID

应该是:

AND WS.EMP_ID   =ES.EMP_ID