1

我有以下查询:

from spl in SpeciesLists 
         join ar in Areas on spl.Station.Area equals ar.Id 
         join ground  in Grounds on ar.Ground equals ground.Id 
         join re in Regions on ground.Region  equals re.Id 
         where spl.Station.Trip.year ==2013
         select new 
           {
              SpciesCommonName = slp.Description,
              Are = ar.description,
              Ground = ground.Code,
              NumberOfTripsInProtectedAreas = "To be calculated",
           }

“行程”可以包括一个或多个站点。保护区字段位于 Trip 表中,可以是 1 或 0。一个站点有一个或多个物种。

如何计算保护区的出行次数?

提前谢谢了

4

1 回答 1

1

您需要在 where 子句中添加 ProtectedArea == 1 的条件。

同样如您的评论中所述,该组将由:slp.Description、ar.description 和 ground.Code

这是代码:

from spl in SpeciesLists 
             join ar in Areas on spl.Station.Area equals ar.Id 
             join ground  in Grounds on ar.Ground equals ground.Id 
             join re in Regions on ground.Region  equals re.Id 
             where spl.Station.Trip.year ==2013
             && spl.Station.Trip.ProtectedArea == 1
             group spl by new { slp.Description, ar.description, ground.Code } into Result
             select new 
               {
                  SpciesCommonName = Result.Key.Description,
                  Are = Result.Key.description,
                  Ground = Result.Key.Code,
                  NumberOfTripsInProtectedAreas = Result.Count()
               }
于 2013-08-22T07:04:22.163 回答