sql语句的结果有问题

时间:2011-08-29 08:02:50

标签: sql oracle

我有一个sql语句,重复一次记录,我不知道为什么!

这是我的陈述:

select   floor((a.created-c.created)*24)
      || ' HOURS ' ||
       mod(floor((a.created-c.created)*24*60),60)
     || ' MINUTES ' ,a.pkey as AssignedGroupResponseTime,a.pkey,d.newString as AssignedGroup

from
(
select g.created,g.issueid as groupid1, ji.pkey ,ci.newString
from   changegroup g
join   jiraissue ji on (ji.id = g.issueid)
join   changeitem ci on (ci.groupid = g.id)
where (g.created, ji.pkey) in (
select min(g.created) ,ji.pkey 
from   changegroup g
join   changeitem ci on (ci.groupid = g.id)
join   jiraissue ji on (ji.id = g.issueid)
join   project p on (p.id = ji.project)
join   priority pr on (pr.id = ji.priority)
where  ci.field = 'Group'
and  ci.oldString like 'Triage' 
and  p.pname = 'Change Management'
and pr.pname='P3'
and  ji.created between '01/03/2011' and  '16/08/2011'
group by ji.pkey
)) a
left join   (
select ji.created, ji.id as groupid2 ,ji.pkey ,ci.newString 
    from   jiraissue ji
    join   changegroup g on (g.issueid = ji.id)
    join   changeitem ci on (ci.groupid = g.id)
    join   project p on (p.id = ji.project)
    where  p.pname = 'Change Management'
    and ci.field = 'Group'
    and  ci.oldString like 'Triage' 
    and  ji.created between '01/03/2011' and  '16/08/2011' 
 ) b ON ( a.pkey = b.pkey)  
 left join (
    select g.created, g.issueid as groupid1 ,ji.pkey ,ci.newString
    from   changegroup g
    join   jiraissue ji on (ji.id = g.issueid)
     join   changeitem ci on (ci.groupid = g.id)
    where (g.created, ji.pkey) in (
    select min(g.created) ,ji.pkey
    from   changegroup g
    join   changeitem ci on (ci.groupid = g.id)
    join   jiraissue ji on (ji.id = g.issueid)
    join   project p on (p.id = ji.project)
    join   priority pr on (pr.id = ji.priority)
    where ci.field='assignee'
    and ci.newString is not NULL
    and  p.pname = 'Change Management'
    and pr.pname='P3'
    and ji.created between '01/03/2011' and  '16/08/2011'
    group by ji.pkey)) c
    ON (c.pkey = a.pkey) 
 left join (
    select g.created, g.issueid as groupid1 ,ji.pkey ,ci.newString
    from   changegroup g
    join   jiraissue ji on (ji.id = g.issueid)
    join   changeitem ci on (ci.groupid = g.id)
    where (g.created, ji.pkey) in (
    select min(g.created) ,ji.pkey 
    from   changegroup g
    join   changeitem ci on (ci.groupid = g.id)
    join   jiraissue ji on (ji.id = g.issueid)
    join   project p on (p.id = ji.project)
    join   priority pr on (pr.id = ji.priority)
    where ci.field='assigned group'
    and ci.newString is not NULL
    and  p.pname = 'Change Management'
    and pr.pname='P3'
    and  ji.created between '01/03/2011' and  '16/08/2011'
    group by ji.pkey)) d
     ON (d.pkey = c.pkey);

1 个答案:

答案 0 :(得分:2)

这是因为您在视图b或c上有重复的键。 您可以单独运行此视图并查看错误(重复键值)。 在那个视图中你加入了。几乎一个连接是在弱条件下进行的。这意味着你有一个条件的重复匹配。