zoukankan      html  css  js  c++  java
  • C#操作mongodb(聚合函数)-分组找出每组的最大值

     public static void OnQuery_QXData(string DBName, string tablename,string layername)
            {
                if (ConnectionString == null) OnCreateDB();
                MoDataBase = MoClient.GetDatabase(DBName);
                var collection = MoDataBase.GetCollection<BsonDocument>(tablename);           

                //{$group:{_id:{stationID:"$stationID",stationName:"$stationName"},TimeData:{$max:"$TimeData"},eValue:{$last:"$eValue"}}}           

                var group = new BsonDocument {

                    {"_id",new BsonDocument
                    {
                        {"stationID","$stationID"},
                        {"stationName","$stationName" }
                    }
            },
                    //{"stationID",new BsonDocument{ { "stationID", "$stationID" } } },
                    {"stationID",new BsonDocument("$last","$stationID")},
                    { "TimeData",new BsonDocument("$max","$TimeData")},
                    {"eValue" ,new BsonDocument("$last","$eValue")}
                };
                var list = collection.Aggregate().Group(group).ToListAsync().Result;
                double value = 0.0;
                foreach (BsonDocument bsondoc in list)
                {
                   
                    double  evalue = double.TryParse(bsondoc.GetElement("eValue").Value.ToString(),out value)?value:0;
                    string stationid = bsondoc.GetElement("stationID").Value.ToString();              
                }
            }
        }
    }

  • 相关阅读:
    HDU 3277 Marriage Match III(最大流+二分+并查集)
    HDU 3032 Nim or not Nim?(博弈,打表找规律)
    2013南京邀请赛小结——ACM两年总结
    HDU 2829 Lawrence (斜率DP)
    HDU 3530 Subsequence(单调队列)
    HDU 1525 Euclid's Game(博弈)
    C Count The Carries(2013南京邀请赛C题)
    A Play the Dice (2013南京邀请赛A题)
    POJ 3017 Cut the Sequence(单调队列+set)
    Jquery TreeView
  • 原文地址:https://www.cnblogs.com/wjr0117/p/9020092.html
Copyright © 2011-2022 走看看