0

目前我正在使用以下查询来显示以下结果。

SELECT * FROM RouteToGrowthRecord, GradeMaster,MileStoneMaster
WHERE MemberID = 'ALV01L11034A06' AND
RouteToGrowthRecord.GradeID=GradeMaster.GradeID AND
RouteToGrowthRecord.MileStoneID=MileStoneMaster.MileStoneID 
ORDER BY CheckupDate DESC

查询的输出是:

现在我有另一个名为的表,它具有与一些附加字段RouteToGrowthRecord_st相同的列。RouteToGrowthRecord

我需要显示两个表中都存在的结果。IE 。如果RouteToGrowthRecord_st给定的有 3 条记录menberID,则输出必须包含另外 3 条记录以及上述查询结果。(fr ex 高于其 9+3=12 条记录)。

4

4 回答 4

0
    SELECT * FROM RouteToGrowthRecord a inner join GradeMaster b inner 
  join MileStoneMaster c inner join  RouteToGrowthRecord_st d on 
    a.GradeID=b.GradeID AND   a.MileStoneID=c.MileStoneID   and
    d.GradeID=b.GradeID AND  d.MileStoneID=c.MileStoneID 
    WHERE a.MemberID = 'ALV01L11034A06' 
    ORDER BY CheckupDate DESC
于 2013-10-01T05:26:34.873 回答
0

您可以通过以下方式编写上述查询

SELECT * FROM RouteToGrowthRecord 
INNER JOIN GradeMaster ON  RouteToGrowthRecord.GradeID=GradeMaster.GradeID
INNER JOIN MileStoneMaster ON RouteToGrowthRecord.MileStoneID=MileStoneMaster.MileStoneID
LEFT JOIN RouteToGrowthRecord_st ON    RouteToGrowthRecord_st.memberID=RouteToGrowthRecord.memberID 
WHERE
RouteToGrowthRecord.MemberID = 'ALV01L11034A06'
order by CheckupDate DESC
于 2013-10-01T05:28:05.853 回答
0

您可以在此处使用 Union 来合并从两个查询中获得的结果。对未映射的附加字段使用默认值。

于 2013-10-01T05:35:22.177 回答
0

这是我的答案

SELECT CheckUpDate,AgeInMonths,PresentWeight,Height,Diagnosis,growthstatus,GradeName,MilestoneName,MemberID
FROM RouteToGrowthRecord, GradeMaster,MileStoneMaster WHERE
 MemberID = 'ALV01L56107A11  ' and 
  RouteToGrowthRecord.GradeID=GradeMaster.GradeID and 
  RouteToGrowthRecord.MileStoneID=MileStoneMaster.MileStoneID 
  union
  SELECT CheckUpDate,AgeInMonths,PresentWeight,Height,Diagnosis,growthstatus,GradeName,MilestoneName,MemberID
   FROM RouteToGrowthRecord_st, GradeMaster,MileStoneMaster WHERE
 MemberID = 'ALV01L56107A11  ' and 
  RouteToGrowthRecord_st.GradeID=GradeMaster.GradeID and 
  RouteToGrowthRecord_st.MileStoneID=MileStoneMaster.MileStoneID 
  order by CheckupDate DESC
于 2013-10-01T08:36:55.823 回答