【问题标题】:Pivot the table result using linq c#使用 linq c# 透视表结果
【发布时间】:2018-07-31 22:41:22
【问题描述】:

想要使用 linq c# 透视此表

My Table is here

【问题讨论】:

  • Stackoverflow 不是代码转换工具!
  • 那么,到目前为止,您尝试过什么,您到底卡在哪里?
  • 希望你得到我的表格结果,我只想使用 linq c# 对其进行旋转
  • 您能解释一下您想要实现的目标吗?请说得更具体一些
  • 那么到目前为止,您编写的代码到底有什么问题?如果您显示该代码,那么也许我们可以提供帮助。

标签: c#


【解决方案1】:

由于该问题没有提供以什么为轴心。我做了一个轴心以计算 50 的周期。将其更改为您的偏好。检查这个fiddle

var result = myList
            .GroupBy(x => x.Branch)
            .Select(y => new {
                           Branch = y.Key, 
                           FirstPeriod = y.Count(z => z.Quantity > 100 && z.Quantity <= 150), 
                           SecondPeriod = y.Count(z => z.Quantity > 150 && z.Quantity <= 200), 
                           ThirdPeriod = y.Count(z => z.Quantity > 200 && z.Quantity <= 250)
                        }).ToList();

参考资料:

Excellent Pivot Example

Method used in the fiddle

【讨论】:

  • 感谢您的宝贵时间...我一直在寻找动态专栏,终于找到了解决方案...再次感谢您的时间和努力...
猜你喜欢
  • 2015-04-25
  • 2023-02-09
  • 2012-04-11
  • 2010-12-07
  • 2016-02-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多