下面逗号分隔的查询sql:
select * from taskdetail td, tasklist tl, f_account fa, tasksort ts where td.flowid = tl.taskprocid and td.taskid = tl.taskid and td.flowowner = fa.fa_account and fa.business_unit not in ('PA005') and tl.tasksortid = ts.tasksortid and tl.taskstatus = '0' and tl.instanceid is null and tl.taskdate > sysdate - 90 and td.stageid != '105' and td.stageid != '1110' and td.flowstatus = '0' and td.flowenddate is not null and td.noresponse != '1'
我想改为join查询,如果用td做基表,tl与ts怎么关联上呢,不知道tl的条件应该怎么写?
我写出以下三条sql,那个是正确的,或者怎么改写呢:
select * from taskdetail td join tasklist tl on td.flowid = tl.taskprocid and td.taskid = tl.taskid and tl.taskstatus = '0' and tl.instanceid is null and tl.taskdate > sysdate - 90 join f_account fa on td.flowowner = fa.fa_account and fa.business_unit not in ('PA005') join tasksort ts on tl.tasksortid = ts.tasksortid where td.stageid != '105' and td.stageid != '1110' and td.flowstatus = '0' and td.flowenddate is not null and td.noresponse != '1'
select * from taskdetail td join tasklist tl on td.flowid = tl.taskprocid and td.taskid = tl.taskid and tl.taskstatus = '0' and tl.instanceid is null and tl.taskdate > sysdate - 90 join f_account fa on td.flowowner = fa.fa_account and fa.business_unit not in ('PA005') join tasksort ts on tl.tasksortid = ts.tasksortid and tl.taskstatus = '0' and tl.instanceid is null and tl.taskdate > sysdate - 90 where td.stageid != '105' and td.stageid != '1110' and td.flowstatus = '0' and td.flowenddate is not null and td.noresponse != '1'
select * from taskdetail td join tasklist tl on td.flowid = tl.taskprocid and td.taskid = tl.taskid join f_account fa on td.flowowner = fa.fa_account and fa.business_unit not in ('PA005') join tasksort ts on tl.tasksortid = ts.tasksortid where td.stageid != '105' and td.stageid != '1110' and td.flowstatus = '0' and td.flowenddate is not null and td.noresponse != '1' and tl.taskstatus = '0' and tl.instanceid is null and tl.taskdate > sysdate - 90
right join tasklist ...
right join f_account..
where
用内连接试试select * from A inner join B on A.id=B.id