注意更新:感谢所有的帮助,对于那些精通vb.net的人来说,这里是自包含的例子......
Structure Stuff
public client as String
public BDate as DateTime
public KB as long
public sub new(client as string, BDate as DateTime, KB as Long)
Me.client = client
Me.BDate = BDate
Me.KB = KB
end sub
End Structure
Sub Main
Dim Stuffs as new List(Of Stuff)
Stuffs.Add(new Stuff("dev0db05", "6/25/2012 7:00:35 AM",1))
Stuffs.Add(new Stuff("dev0db05", "6/25/2012 7:00:35 AM",1))
Stuffs.Add(new Stuff("dev0db05", "6/25/2012 7:00:35 AM",1))
Stuffs.Add(new Stuff("dev0db05", "6/26/2012 7:00:35 AM",2))
Stuffs.Add(new Stuff("dev0db05", "6/26/2012 7:00:35 AM",2))
Stuffs.Add(new Stuff("dev0db05", "6/26/2012 7:00:35 AM",2))
Stuffs.Add(new Stuff("dev0db05", "6/27/2012 7:00:35 AM",3))
Stuffs.Add(new Stuff("dev0db05", "6/27/2012 7:00:35 AM",3))
Stuffs.Add(new Stuff("dev0db05", "6/27/2012 7:00:35 AM",3))
Stuffs.Add(new Stuff("dev0db05", "6/28/2012 7:00:35 AM",4))
Stuffs.Add(new Stuff("dev0db05", "6/28/2012 7:00:35 AM",4))
Stuffs.Add(new Stuff("dev0db05", "6/28/2012 7:00:35 AM",4))
dim q = From c In Stuffs _
where c.client= "dev0db05" _
order by c.BDate _
group c by c.Client,c.bdate into g = group _
select ClientName = Client, BDate = DateTime.Parse(bdate).ToShortDateString, SumKB = g.sum(Function(p) p.kb)
Output:
ClientName BDate SumKB
dev0db05 6/25/2012 3
dev0db05 6/26/2012 6
dev0db05 6/27/2012 9
dev0db05 6/28/2012 12
所以在这个例子中,我只想为dev0db05返回最高的SumKB(12)我知道我必须做一个MAX但不知道如何反对上述......谢谢,可能太简单了,但我在失利 ...
对于下面的 Linq 查询,如何只返回最大值,即 259835919?谢谢!我是一个新手,并试图理解。
dim q = From c In Stuff _
where c.client= "dev0db05" _
where c.policy = "mcg-oracle-db" _
order by c.BackupDate _
group c by key = 0, c.Client,c.backupdate into g = group _
select ClientName = Client, BDate = DateTime.Parse(backupdate).ToShortDateString, SumKB = g.sum(Function(p) p.kilobytes)
返回:
dev0db05 5/20/2012 163160396
dev0db05 5/27/2012 235918153
dev0db05 6/3/2012 259813647
dev0db05 6/10/2012 259835151
dev0db05 6/13/2012 23824838
dev0db05 6/14/2012 259578160
dev0db05 6/15/2012 23864427
dev0db05 6/16/2012 259578127
**dev0db05 6/17/2012 259835919**
dev0db05 6/18/2012 23858283
dev0db05 6/19/2012 259575055
dev0db05 6/20/2012 33412