2 u010668850 u010668850 于 2014.06.16 11:38 提问

急,sql通过多列的值选择连接多表的问题!
sql

语句有点长,见谅哈!
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表

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!