2

我有一个带有列的表OneStopPrice; MultiStopPrice; NonStopPrice。我想拥有Min()所有 3 列。但是如果Min()任何一列是0,它必须被忽略。

OneStop | NonStop | MultiStop
-----------------------------
233.23  | 0.0     | 355.23

此处的 NonStop 必须被视为最高值以便忽略它。

有人对此有想法LinQ吗?

我使用查询如下:

var data = odyResults.GroupBy(logEle => new { logEle.Air.FromCity, logEle.Air.ToCity }, (key, group) => new{
       FromCity = key.FromCity,
       ToCity = key.ToCity,
       OneStopPrice = group.Min(x=>x.Air.OneStopPrice),
       MultiStopPrice = group.Min(x => x.Air.MultiStopPrice),
       NonStopPrice = group.Min(x => x.Air.NonStopPrice),
       FromToCityCount = group.Count()
      });
4

1 回答 1

2

只需过滤掉零:

NonStopPrice = group.Where(x => x.Air.NonStopPrice > 0)
                    .Min(x => x.Air.NonStopPrice),
于 2013-10-30T11:11:00.483 回答