<small id='QF4A9'></small><noframes id='QF4A9'>

    • <bdo id='QF4A9'></bdo><ul id='QF4A9'></ul>
    <legend id='QF4A9'><style id='QF4A9'><dir id='QF4A9'><q id='QF4A9'></q></dir></style></legend>

      <tfoot id='QF4A9'></tfoot>
      <i id='QF4A9'><tr id='QF4A9'><dt id='QF4A9'><q id='QF4A9'><span id='QF4A9'><b id='QF4A9'><form id='QF4A9'><ins id='QF4A9'></ins><ul id='QF4A9'></ul><sub id='QF4A9'></sub></form><legend id='QF4A9'></legend><bdo id='QF4A9'><pre id='QF4A9'><center id='QF4A9'></center></pre></bdo></b><th id='QF4A9'></th></span></q></dt></tr></i><div id='QF4A9'><tfoot id='QF4A9'></tfoot><dl id='QF4A9'><fieldset id='QF4A9'></fieldset></dl></div>

      1. Linq 按日期获取数据组的总和

        时间:2023-06-05

          1. <tfoot id='FreVW'></tfoot>
            <i id='FreVW'><tr id='FreVW'><dt id='FreVW'><q id='FreVW'><span id='FreVW'><b id='FreVW'><form id='FreVW'><ins id='FreVW'></ins><ul id='FreVW'></ul><sub id='FreVW'></sub></form><legend id='FreVW'></legend><bdo id='FreVW'><pre id='FreVW'><center id='FreVW'></center></pre></bdo></b><th id='FreVW'></th></span></q></dt></tr></i><div id='FreVW'><tfoot id='FreVW'></tfoot><dl id='FreVW'><fieldset id='FreVW'></fieldset></dl></div>

            <small id='FreVW'></small><noframes id='FreVW'>

                • <bdo id='FreVW'></bdo><ul id='FreVW'></ul>

                    <tbody id='FreVW'></tbody>
                • <legend id='FreVW'><style id='FreVW'><dir id='FreVW'><q id='FreVW'></q></dir></style></legend>
                • 本文介绍了Linq 按日期获取数据组的总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我的数据如下:

                   read_date |  T1  |  T2  |
                  15.02.2000 |   2  |   3  |
                  16.02.2000 |   4  |   5  |
                  15.03.2000 |   2  |   3  |
                  16.03.2000 |   5  |   4  |
                  

                  我想得到 T1 和 T2 的总和,像这样:

                  I want to get mountly sum of T1 and T2, like this:

                   read_date |  T1  |  T2  |
                     02.2000 |   6  |   8  |
                     03.2000 |   7  |   7  |   
                  

                  我试着写这样的东西:

                  var result = from s in meter_readings.Take(10)
                               group s by new { s.read_date} into g
                               select new
                               {
                                   read_date = g.Key.read_date,
                                   T1 = g.Sum(x => x.T1),
                                   T2 = g.Sum(x => x.T2)
                               };
                  

                  但这并没有给出预期的数据.有没有给出数据每小时总和,每日总和等的例子.

                  but this does not give expected data.Is there any example to give data hourly sums, daily sums, etc.

                  谢谢

                  推荐答案

                  分组时只考虑年份和月份:

                  You should only take the year and month into account when grouping:

                  var result = 
                      from s in  meter_readings.Take(10)
                      group s by new { date = new DateTime(s.read_date.Year, s.read_date.Month, 1) } into g
                      select new
                      {
                          read_date = g.Key.date,
                          T1 = g.Sum(x => x.T1),
                          T2 = g.Sum(x => x.T2)
                      };
                  

                  这篇关于Linq 按日期获取数据组的总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何计算 LINQ 中 DataTable 的列的总和(到数据集) 下一篇:如何在 C# 中对两个字典中的值求和?

                  相关文章

                  最新文章

                  • <bdo id='iJbSP'></bdo><ul id='iJbSP'></ul>
                  1. <tfoot id='iJbSP'></tfoot>

                    <i id='iJbSP'><tr id='iJbSP'><dt id='iJbSP'><q id='iJbSP'><span id='iJbSP'><b id='iJbSP'><form id='iJbSP'><ins id='iJbSP'></ins><ul id='iJbSP'></ul><sub id='iJbSP'></sub></form><legend id='iJbSP'></legend><bdo id='iJbSP'><pre id='iJbSP'><center id='iJbSP'></center></pre></bdo></b><th id='iJbSP'></th></span></q></dt></tr></i><div id='iJbSP'><tfoot id='iJbSP'></tfoot><dl id='iJbSP'><fieldset id='iJbSP'></fieldset></dl></div>
                  2. <legend id='iJbSP'><style id='iJbSP'><dir id='iJbSP'><q id='iJbSP'></q></dir></style></legend>

                      <small id='iJbSP'></small><noframes id='iJbSP'>