使用当前查询的结果作为其自身的字段

时间:2014-01-30 21:00:31

标签: sql oracle correlated-subquery

基本上,我想根据自身的结果查询一个表,作为其Select语句的一部分

select error_log.err_rfp_num                                                                as task_id,
   error_log.descr                                                                          as task_desc,
   error_log.user_id                                                                        as entered_by,
   error_log.ctrl_date || ' ' || error_log.ctrl_time    as entered_datetime,
   error_log.task_type_cd,
   task_type.descr                                      as task_type_desc,
   client.client_num                                    as client_cd,
   client.descr                                                                                 as client_name,
   error_log.reported_by,
   product.descr                                                                                as product_name,
   product_ver.descr                                                                        as product_version,
   error_log.module_cd,
   error_log.proj_cd                                                                        as parent_task_id,
   (
      select error_log.descr 
      from error_log
      where error_log.err_rfp_num = error_log.proj_cd
   )                                                    as parent_task_desc,
     error_log.task_status
    FROM error_log
    inner   join client
     on (client.client_num = error_log.client_num)
    inner   join product
     on (product.product_num = error_log.product_num)
    inner join task_type
     on error_log.task_type_cd = task_type.task_type_cd
    inner    join product_ver
     on (product_ver.version_num = error_log.version_num AND product_ver.product_num = error_log.product_num)
    left outer join error_status
     on error_status.status_num = error_log.task_status
    and error_status.product_num = 74
    where error_log.task_status in ('1', '2', '3')

parent_task_desc(error_log.proj_cd)只是error_log.err_rfp_num的描述。

父任务和子任务都在一个表中

如何设置select语句以在查询本身中使用查询结果?

0 个答案:

没有答案