简体   繁体   English

使用Linq以正确的顺序对数据列表进行分组和组织

[英]Use Linq to group and organise list of data in correct order

I have the following data table and i need to group it by quarters. 我有以下数据表,我需要按季度将其分组。 I basically need to show Jan totals which will be including Jan Feb Mar then i need to show Apr totals which will include Apr May Jun and so on down the list. 我基本上需要显示一月总计,其中包括一月二月三月,然后我需要显示四月总计,其中包括四月,五月,六月,等等。 I also need to show offpeak and years in the same order 我还需要以相同的顺序显示非高峰和年份
要使用的数据表

If you can "groom" your data so that the months are represented as an integer number 0 - 11, then you can group them into quarters by grouping on int(month / 3) . 如果可以“整理”数据,使月份以0-11的整数表示,则可以通过对int(month / 3)分组将它们分组为四分之一。 Jan(0), Feb(1), March(2) div 3 all = 0. April(3), May(4), June(5) div 3 all = 1, etc. The Quarter number (Q1, Q2, etc) is int(month / 3) + 1 一月(0),二月(1),三月(2)div 3全部=0。四月(3),五月(4),六月(5)div 3全部= 1,等等。四分位数(Q1,Q2,等等)是int(month / 3) + 1

If the months are stored in the database as strings, you'll have to write a mapping function to reduce the string name to the month number (switch statement), and pray that this app is never used or seen by anyone other than English speakers. 如果月份以字符串形式存储在数据库中,则必须编写一个映射函数以将字符串名称简化为月份号(switch语句),并祈祷除讲英语的人外,任何人都不会使用或看到此应用程序。 ;> ;>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM