select a1.personname,a3.workName from
(--查询所有人与所有任务的集合
select t1.personname,t2.workid from
(select personname from T人完成的任务 group by personname) t1 ,
(select workid from T任务表 group by T任务表) t2 ) a1 left join
(--查询人完成任务的集合
select t1.personname,t2.workid from T人完成的任务 T1 innerJOIN T任务表 T2
ON T1.finishworkid=T2.WORKID ) a2
on a1.personname=a2.personname and a1.workid=a2.workid
left join T任务表 a3 on a1.workid=a3.workid
where a2.workid is null
这样是否可以:
用人和任务的全部组合减去完成的任务.
--SQL中用except关键字
--oracle没用过,用minus试试
select distinct personname,workname
from finishwork,work
except
select personname,workname
from finishwork inner join work on finishwork.finishworkid=work.workid
我刚试了下.是可以的.