这是Linqpad:
var tuples = new[] {
Tuple.Create(1, 2012, 1, 1),
Tuple.Create(1, 2012, 1, 2),
Tuple.Create(1, 2012, 1, 3),
Tuple.Create(1, 2012, 1, 4),
Tuple.Create(1, 2012, 1, 5),
Tuple.Create(1, 2012, 2, 6),
Tuple.Create(1, 2012, 2, 7),
Tuple.Create(1, 2012, 2, 8),
Tuple.Create(1, 2012, 2, 9),
Tuple.Create(1, 2012, 2, 10),
Tuple.Create(1, 2013, 2, 1),
Tuple.Create(1, 2013, 2, 13),
Tuple.Create(1, 2013, 2, 14),
Tuple.Create(1, 2013, 2, 15),
Tuple.Create(1, 2013, 2, 16),
Tuple.Create(1, 2013, 3, 17),
Tuple.Create(1, 2013, 3, 18),
Tuple.Create(1, 2013, 3, 19),
Tuple.Create(1, 2013, 3, 20),
Tuple.Create(1, 2013, 3, 21)};
tuples
.GroupBy(t => t.Item3)
.Select (g => g.Where(x => x.Item2 == g.Max (x1 => x1.Item2)))
.Dump();
所以,你得到的最高的一年,你找到了一个学期的学期。
输出:
Item1 Item2 Item3 Item4
1 2012 1 1
1 2012 1 2
1 2012 1 3
1 2012 1 4
1 2012 1 5
Item1 Item2 Item3 Item4
1 2013 2 1
1 2013 2 13
1 2013 2 14
1 2013 2 15
1 2013 2 16
Item1 Item2 Item3 Item4
1 2013 3 17
1 2013 3 18
1 2013 3 19
1 2013 3 20
1 2013 3 21
你能写,你要检索,像上面表中的数据?我的意思是你可以写结果数据表吗? – 2013-05-09 13:23:35
@AliRızaAdıyahşi我想选择2012年第1学期加上2013学期2和3 – 2013-05-09 13:29:58
@AqilAzad:你为什么要这样做?鉴于表格,它为什么你需要这样做没有任何意义。 *用户*告诉你他们想要哪些年/学期?或者,这只是一个简单的例子:“我想要查询结果?” – user7116 2013-05-09 13:35:09