0

私はこのテーブルを持っています

EquipmentId  Value  Date
1            2      11/04/2013
1            1      11/04/2013
2            3      11/04/2013
2            2      10/04/2013
2            5      10/04/2013
3            1      10/04/2013
3            3      11/04/2013

これらのアイテムを日付ごとにグループ化し、日付をキーとして、その日のすべての機器値の最大値の合計を持つ辞書を作成したい

結果はこのようになります

[10/04/2013: 6]   // 6 = 5 (as the max of values of the the equipmetId 2) + 1 (as the max of values of the the equipmetId 3)
[11/04/2013: 5]   // 5 = 2(as the max of values of the the equipmetId 1) + 3(as the max of values of the the equipmetId 3)

合計なしでこれを取得するためのクエリを作成することができました。つまり、1 つの機器のみを意味します。

var consumptionValues = (from c in context.ConsumptionSet
                         join pi in context.PropertiesInstanceSet on c.PropertiesInstanceID equals pi.PropertiesInstanceID
                         join ep in context.EquipmentPropertiesSet on pi.EquipmentPropertiesID equals ep.EquipmentPropertiesID
                         join e in context.EquipmentSet on ep.EquipmentID equals e.EquipmentID
                         where (e.EquipmentID == equipmentId && pi.ProprietesName == ProprietesName.Energy && c.Date <= DateTime.Now && c.Date >= firstDayDate)
                         group c by SqlFunctions.DatePart("weekday", c.Date) into grp
                         select new
                         {
                             dayOfWeek = (DayOfWeek)grp.Key.Value - 1,
                             value = grp.Max(c => c.Value),
                         }).ToDictionary(c => c.dayOfWeek.ToString(), c => c.value);

これは、すべての結合を含む完全なクエリです。この例では、単純化した例を示しました。

単一のクエリでこれを行うことは可能ですか?

4

1 に答える 1