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])))

第二个查询完全相同,但该函数在查询的最后采用另一个字段

我已经尝试过 UNION 运算符,但 LLBLGEN pro 不支持 UNION 运算符我怎样才能使这个 int oa 成为检索两个结果集的单个查询?

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

这是一种重写查询的奇怪方法,但您也可以尝试这样的事情:

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]))
)

将这两个WHERE子句放在同一个查询中,并OR在它们之间加上一个。同样在您的第一个查询中,您似乎在重复最后一行,我不确定您为什么需要这样做。

于 2012-09-28T10:45:23.390 回答
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 回答