在下面的sql里,表(ins_incident)中没有字段(process_def_start_date).可执行时没报错,是什么原因啊with main as(  select distinct
 incident_id,
 instance_id,
 instance_state,
 allocate_party_id,
 complete_party_id,
 case when complete_party_id is null then allocate_party_id
      else complete_party_id
  end as partyId,
 allocated_date,
 activity_id,
 instance_start_date
 from ins_instance it   
where incident_id = '20100601001'   
order by instance_start_date desc,instance_id desc
 )
select distinct
       m.*,
       u.user_name,
       a.activity_name
  from main m inner 
  join mst_user u
    on u.party_id = m.partyId
   and u.start_date =
       (select max(start_date)
          from mst_user
         where party_id = u.party_id
         and start_date <= '2010-06-02 15:05:24.219'
        )
   and u.delete_flag = false
  join def_activity a
    on a.activity_id = m.activity_id
   and a.process_id =
       (select process_id
         from ins_incident
        where incident_id = m.incident_id
          and delete_flag = false
        )
   and a.process_def_start_date =
       (select process_def_start_date
          from ins_incident
         where incident_id = m.incident_id
           and delete_flag = false
        )
   order by instance_start_date desc,instance_id desc

解决方案 »

  1.   

    没这字段能出来结果吗
    show create table ins_incident看看
      

  2.   

    先加个别名试试
    select t.process_def_start_date 
      from ins_incident t
    或者你把and a.process_def_start_date =
      (select process_def_start_date
      from ins_incident
      where incident_id = m.incident_id
      and delete_flag = false
      )
    之前的条件满足的数据添加上,再执行到这块时,估计会出错了。
      

  3.   

    and a.process_def_start_date =
      (select process_def_start_date
      from ins_incident
      where incident_id = m.incident_id
      and delete_flag = false
      )
    子查询的select可以检索外面的表(联合查询的表)的字段
    process_def_start_date就是a表的字段