u010668850 于 2014.06.16 11:38 提问

select * from ( select
c.RQID PR,
a.URL,
a.Name ,
ROW_NUMBER() over(PARTITION by c.RQID order by b.ExecutedTime) as num
from PR a

inner join PRAC b on a.PRId=b.PRId
inner join RQ c on b.PRId=c.PRId
left join PC2 p on p.PRId=b.PRId
where a.Status=b.Status and a.Name='CR'

union
select
c.RQID PR,
a.URL,
a.Name,
ROW_NUMBER() over(PARTITION by c.RQID order by b.ExecutedTime) as num
from PR a

inner join PRAC b on a.PRId=b.PRId
inner join RQ c on b.PRId=c.PRId
left join PC1 p on p.PRId=b.PRId
where a.Status=b.Status and a.Name='CR'

union
select
e.RQID PR,
a.URL,
a.Name,
ROW_NUMBER() over(PARTITION by e.RQID order by b.ExecutedTime ) as num
from PR a
inner join PRAC b on a.PRId=b.PRId
inner join RQ_IR e on e.PRId=b.PRId
left join PC_IR p on p.PRId=b.PRId
where a.Status=b.Status and a.Name='IR'
union
select
f.RQID PR,
a.URL,
a.Name,
ROW_NUMBER() over(PARTITION by f.RQID order by b.ExecutedTime ) as num
from PR a

inner join PRAC b on a.PRId=b.PRId
inner join RQ f on f.PRId=b.PRId
left join PC_PCE p on p.PRId=b.PRId
where a.Status=b.Status and a.Name='PCE' ) t where t.num<=1

SQL 语句如上 a.Name='CR' 的时候我想通过a.url的值连判断连接PC1表还是PC2表