1
select * from ProjectFeature pf
inner join ProjectArea pa
on pa.AreaId = pf.AreaId
inner join Project p
on p.ProjectId = pa.ProjectId
where (p.ProjectId=175 AND pf.FeatureStatusTypeId=2
AND (pf.FeatureId IN (SELECT dbo.[MaxFeatureVersoinId](pf.FeatureId) AS [FeatureId])) AND (pf.FeatureId IN (SELECT dbo.[MaxFeatureVersoinId](pf.FeatureId) AS [FeatureId])))

別のクエリがあります

select * from ProjectFeature pf
inner join ProjectArea pa
on pa.AreaId = pf.AreaId
inner join Project p
on p.ProjectId = pa.ProjectId
where (p.ProjectId=175 AND pf.FeatureStatusTypeId=2
AND (pf.FeatureId IN (SELECT dbo.[MaxFeatureVersoinId](pf.FeatureId) AS [FeatureId])) AND (pf.FeatureId IN (SELECT dbo.[MaxFeatureVersoinId](pf.ChangeRequestToFeatureId) AS [FeatureId])))

2 番目のクエリはまったく同じですが、関数はクエリの最後で別のフィールドを取得します。

UNION 演算子を試しましたが、LLBLGEN pro は UNION 演算子をサポートしていません。これを両方の結果セットを取得する単一のクエリにするにはどうすればよいですか?

4

3 に答える 3

1
select * from ProjectFeature pf
inner join ProjectArea pa
on pa.AreaId = pf.AreaId
inner join Project p
on p.ProjectId = pa.ProjectId
where (p.ProjectId=175 AND pf.FeatureStatusTypeId=2
AND ((pf.FeatureId IN (SELECT dbo.[MaxFeatureVersoinId](pf.FeatureId) AS [FeatureId])) 
OR (pf.FeatureId IN (SELECT dbo.[MaxFeatureVersoinId](pf.ChangeRequestToFeatureId) AS [FeatureId]))))

冗長性を取り除いたので、リクエストを減らすことができます

于 2012-09-28T11:04:15.917 に答える
0

結果を同じクエリの下に別の行として追加する場合は、列とデータ型がまったく同じであればUNION、同じものを使用できます。

select * from ProjectFeature pf
inner join ProjectArea pa
on pa.AreaId = pf.AreaId
inner join Project p
on p.ProjectId = pa.ProjectId
where (p.ProjectId=175 AND pf.FeatureStatusTypeId=2
AND (pf.FeatureId IN (SELECT dbo.[MaxFeatureVersoinId](pf.FeatureId) AS [FeatureId])) AND (pf.FeatureId IN (SELECT dbo.[MaxFeatureVersoinId](pf.FeatureId) AS [FeatureId])))
UNION
select * from ProjectFeature pf
inner join ProjectArea pa
on pa.AreaId = pf.AreaId
inner join Project p
on p.ProjectId = pa.ProjectId
where (p.ProjectId=175 AND pf.FeatureStatusTypeId=2
AND (pf.FeatureId IN (SELECT dbo.[MaxFeatureVersoinId](pf.FeatureId) AS [FeatureId])) AND (pf.FeatureId IN (SELECT dbo.[MaxFeatureVersoinId](pf.ChangeRequestToFeatureId) AS [FeatureId])))
于 2012-09-28T10:35:20.440 に答える
0

これはクエリを書き直すちょっと変わった方法ですが、次のような方法を試すこともできます。

select * 
from ProjectFeature pf
inner join ProjectArea pa
  on pa.AreaId = pf.AreaId
inner join Project p
  on p.ProjectId = pa.ProjectId
where 
(
  p.ProjectId=175 
  AND pf.FeatureStatusTypeId=2
  AND (pf.FeatureId IN (SELECT dbo.[MaxFeatureVersoinId](pf.FeatureId) AS [FeatureId])) 
  AND (pf.FeatureId IN (SELECT dbo.[MaxFeatureVersoinId](pf.FeatureId) AS [FeatureId]))
)
OR
(
  p.ProjectId=175 
  AND pf.FeatureStatusTypeId=2
  AND (pf.FeatureId IN (SELECT dbo.[MaxFeatureVersoinId](pf.FeatureId) AS [FeatureId])) 
  AND (pf.FeatureId IN (SELECT dbo.[MaxFeatureVersoinId](pf.ChangeRequestToFeatureId) AS [FeatureId]))
)

2 つのWHERE句を同じクエリに配置し、ORその間に を配置します。また、最初のクエリでは、最後の行を繰り返しているように見えますが、なぜそれを行う必要があるのか​​ わかりません。

于 2012-09-28T10:45:23.390 に答える