日期:2014-05-20 浏览次数:21063 次
static void Main(string[] args) { var list = GetData(); var query = from u in list where u.IsNormal == "1" group u by u.UserId into g orderby g.Key from u2 in g where u2.Date == g.Min(u3 => u3.Date) select u2; foreach (var u in query) Console.WriteLine("{0}, {1}, {2}", u.UserId, u.Date, u.Rank); Console.Read(); } static IEnumerable<User> GetData() { yield return new User { UserId = "100", Rank = "10", Date = "20101012", IsNormal = "1" }; yield return new User { UserId = "100", Rank = "20", Date = "20101009", IsNormal = "1" }; yield return new User { UserId = "200", Rank = "11", Date = "20101011", IsNormal = "1" }; yield return new User { UserId = "100", Rank = "18", Date = "20101008", IsNormal = "1" }; yield return new User { UserId = "300", Rank = "2", Date = "20101010", IsNormal = "1" }; yield return new User { UserId = "300", Rank = "15", Date = "20101013", IsNormal = "1" }; yield return new User { UserId = "300", Rank = "16", Date = "20101002", IsNormal = "0" }; }