我正在开发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_为null)的任务,这些任务不能分配给这个用户(‘my_id’),并且需要技能' my _ skill _1‘。在activiti中,ACT_RU_IDENTITYLINK表包含任务和技能(GROUP_ID_)之间的链接,ACT_RU_VARIABLE包含与任务关联的变量的信息(这里我们确保变量'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。exist/not exist是这样工作的吗?我认为在子查询中我们也需要引用外部表(ACT_RU_IDENTITYLINK)。
发布于 2019-11-19 15:37:54
我认为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;https://stackoverflow.com/questions/58926429
复制相似问题