【问题标题】:exists/not exists without referring to outer table存在/不存在而不参考外部表
【发布时间】:2020-03-14 12:33:16
【问题描述】:

我正在开发 Activiti 框架。这是java中的工作流自动化框架。我有以下查询:

select RES.* from ACT_RU_TASK RES where exists 
(select 1 from ACT_RU_IDENTITYLINK I where not exists
   (
    select 1 from ACT_RU_VARIABLE A0 where RES.ID_ = A0.TASK_ID_ and A0.NAME_= 'excludedUserForTask'
    and A0.TYPE_ = 'string' and A0.TEXT_ ='my_id'
   )
   and I.TASK_ID_ = RES.ID_ and I.TYPE_ = 'candidate' and I.GROUP_ID_ IN ('my_skill_1')
)
and 
RES.ASSIGNEE_ is null order by RES.priority_ desc ,RES.create_time_ LIMIT 10 OFFSET 0;

所以,我的目标是获取所有尚未分配的任务(从表 ACT_RU_TASK)(RES.ASSIGNEE_ 为空),并且不能分配给该用户('my_id'),并且需要技能'my_skill_1 '。在activiti中,ACT_RU_IDENTITYLINK表包含了一个task和一个skill(GROUP_ID_)的链接,ACT_RU_VARIABLE包含了一个task相关的变量信息(这里我们保证变量'excludedUserForTask'和'my_id'没有配对)。

但我面临的问题是,除了需要技能“my_skill_1”的任务外,我还有其他需要其他技能的任务。

查看查询,我不确定这部分:

   select 1 from ACT_RU_IDENTITYLINK I where not exists
   (
    select 1 from ACT_RU_VARIABLE A0 where RES.ID_ = A0.TASK_ID_ and A0.NAME_= 'excludedUserForTask'
    and A0.TYPE_ = 'string' and A0.TEXT_ ='my_id'
   )
   and I.TASK_ID_ = RES.ID_ and I.TYPE_ = 'candidate' and I.GROUP_ID_ IN ('my_skill_1')

在 NOT EXISTS 的子查询中,我们不是指 ACT_RU_IDENTITYLINK。存在/不存在以这种方式工作吗?我认为我们也需要在子查询中引用外部表(ACT_RU_IDENTITYLINK)。

【问题讨论】:

    标签: sql exists activiti not-exists


    【解决方案1】:

    我相信not exists 部分必须是这样的外部查询条件的一部分

    select RES.* 
    from ACT_RU_TASK RES 
    where exists 
        (
            select 1 
            from ACT_RU_IDENTITYLINK I 
                and I.TASK_ID_ = RES.ID_ 
                and I.TYPE_ = 'candidate' 
                and I.GROUP_ID_ IN ('my_skill_1')
        ) 
        and not exists
        (
            select 1 
            from ACT_RU_VARIABLE A0 
            where RES.ID_ = A0.TASK_ID_ 
              and A0.NAME_= 'excludedUserForTask'
              and A0.TYPE_ = 'string' and A0.TEXT_ ='my_id'
        )
        and RES.ASSIGNEE_ is null 
    order by RES.priority_ desc ,RES.create_time_ 
    LIMIT 10 OFFSET 0;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-22
      • 1970-01-01
      • 2013-06-26
      • 1970-01-01
      • 2017-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多