精华内容
下载资源
问答
  • aggregate

    2020-12-28 20:38:46
    <div><p>aggregate ^.pre.<em>.<>.m1_rate ^.pre.</em>.<>.m5_rate ^.pre.<em>.<>.p98 ^.pre.</em>.<>.p75 ^.pre.*.<>.mean every 10 seconds expire after 35 seconds ...
  • Aggregate

    2016-10-12 10:04:00
    https://msdn.microsoft.com/en-us/library/bb549218(v=vs.110).... public static TAccumulate Aggregate<TSource, TAccumulate>(this IEnumerable<TSource> source, TAccumulate seed, Func<TAcc...

    https://msdn.microsoft.com/en-us/library/bb549218(v=vs.110).aspx

    public static TAccumulate Aggregate<TSource, TAccumulate>(this IEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> func);

    Parameters

    source
    Type: System.Collections.Generic.IEnumerable<TSource>

    An IEnumerable<T> to aggregate over.

    seed
    Type: TAccumulate

    The initial accumulator value.

    func
    Type: System.Func<TAccumulate, TSource, TAccumulate>

    An accumulator function to be invoked on each element.

    举例:

    https://www.codewars.com/kata/beginner-reduce-but-grow/train/csharp

    对数组中的元素,计算累乘

    using System.Linq;
    
    public class Kata
    {
        public static int Grow(int[] x)
        {
            return x.Aggregate(1, (current, item) => current * item);
        }
    }

     

    求和:

    return Enumerable.Range(3, n - 3 + 1).Where(x => x%3 == 0 || x%5 == 0).Aggregate(0, (current, item) => current + item);

    where之后可以直接Sum

     

    转载于:https://www.cnblogs.com/chucklu/p/5951708.html

    展开全文
  • Aggregate-源码

    2021-03-27 23:32:50
    Aggregate
  • <div><p>what is the difference between aggregateId and aggregate root? is aggregate id the same as id of aggregate root? </p><p>该提问来源于开源项目:gregoryyoung/m-r</p></div>
  • Aggregate options

    2020-12-01 13:46:31
    <div><p>Refactoring aggregate options <p>http://php.net/manual/ru/mongocollection.aggregate.php https://docs.mongodb.org/manual/reference/command/aggregate/#dbcmd.aggregate ...
  • Aggregate Functions

    2019-06-10 12:27:43
    2.7. Aggregate Functions Like most other relational database products, PostgreSQL supports aggregate functions. An aggregate function computes a single result from multiple input rows. For example, t...

    2.7. Aggregate Functions

    Like most other relational database products, PostgreSQL supports aggregate functions. An aggregate function computes a single result from multiple input rows. For example, there are aggregates to compute the count, sum, avg (average), max (maximum) and min (minimum) over a set of rows. 

     

    As an example, we can find the highest low-temperature reading anywhere with:

    SELECT max(temp_lo) FROM weather;

    max

    -----

    46

    (1 row)

    If we wanted to know what city (or cities) that reading occurred in, we might try:

    SELECT city FROM weather WHERE temp_lo = max(temp_lo); WRONG

    but this will not work since the aggregate max cannot be used in the WHERE clause. (This restriction exists because the WHERE clause determines which rows will be included in the aggregate calculation; so obviously it has to be evaluated before aggregate functions are computed.) However, as is often the case the query can be restated to accomplish the desired result, here by using a subquery:

    SELECT city FROM weather

    WHERE temp_lo = (SELECT max(temp_lo) FROM weather);

    city

    ---------------

    San Francisco

    (1 row)

    This is OK because the subquery is an independent computation that computes its own aggregate separately from what is happening in the outer query.

     

    Aggregates are also very useful in combination with GROUP BY clauses. For example, we can get the maximum low temperature observed in each city with:

    SELECT city, max(temp_lo)

    FROM weather

    GROUP BY city;

    city | max

    ---------------+-----

    Hayward | 37

    San Francisco | 46

    (2 rows)

    which gives us one output row per city. Each aggregate result is computed over the table rows matching that city. We can filter these grouped rows using HAVING:

    SELECT city, max(temp_lo)

    FROM weather

    GROUP BY city

    HAVING max(temp_lo) < 40;

    city | max

    ---------+-----

    Hayward | 37

    (1 row)

    which gives us the same results for only the cities that have all temp_lo values below 40. Finally, if we only care about cities whose names begin with “S”, we might do:

    SELECT city, max(temp_lo)

    FROM weather

    WHERE city LIKE 'S%' -- The LIKE operator does pattern matching and is explained in Section 9.7.

    GROUP BY city

    HAVING max(temp_lo) < 40;

    It is important to understand the interaction between aggregates and SQL's WHERE and HAVING clauses. The fundamental difference between WHERE and HAVING is this: WHERE selects input rows before groups and aggregates are computed (thus, it controls which rows go into the aggregate computation),whereas HAVING selects group rows after groups and aggregates are computed. Thus, the WHERE clause must not contain aggregate functions; it makes no sense to try to use an aggregate to determine which rows will be inputs to the aggregates. On the other hand, the HAVING clause always contains aggregate functions. (Strictly speaking, you are allowed to write a HAVING clause that doesn't use aggregates, but it's seldom useful. The same condition could be used more efficiently at the WHERE stage.)

     

    In the previous example, we can apply the city name restriction in WHERE, since it needs no aggregate.This is more efficient than adding the restriction to HAVING, because we avoid doing the grouping and aggregate calculations for all rows that fail the WHERE check.

     

    2.7 聚合函数

    像其他数据库产品一样,PostgreSQL支持聚合函数。聚合函数将多行输出处理后,输出为一行。例如:有计算数据中的总个数、总和、平均值、最大值、最小值的聚合函数。

     

    例如,可以通过以下语句获取各个城市low-temperature中的最大值:

    SELECT max(temp_lo) FROM weather;

    max

    -----

    46

    (1 row)

    如果想要知道返回的数值是属于哪个城市的,那么你可能会执行下面的错误语句:

    SELECT city FROM weather WHERE temp_lo = max(temp_lo); WRONG

    因为聚合函数max不能放到where中,所以上面的语句会报错。(存在这个限制的原因是,where子句限定了需要聚合函数计算的数据集,所以where子句中的数据要在使用聚合函数之前选出来,所以where子句中不能使用聚合函数)。然而,可以使用子查询满足要求:

    SELECT city FROM weather

    WHERE temp_lo = (SELECT max(temp_lo) FROM weather);

    city

    ---------------

    San Francisco

    (1 row)

    子查询与外部查询相互独立的,所以这里可以使用聚合函数。

     

    聚合函数与group by配合使用,效果更好。比如,我们可以使用以下语句获得监测到的每个城市的最低温度:

    SELECT city, max(temp_lo)

    FROM weather

    GROUP BY city;

    city | max

    ---------------+-----

    Hayward | 37

    San Francisco | 46

    (2 rows)

    上面的查询,每个城市给出一个结果。每个聚合结果是通过对符合条件的行进行计算得到的。我们还可以使用HAVING对聚合结果进行筛选:

    SELECT city, max(temp_lo)

    FROM weather

    GROUP BY city

    HAVING max(temp_lo) < 40;

    city | max

    ---------+-----

    Hayward | 37

    (1 row)

    这样只会返回temp_lo均低于40的行。当然,如果我们只想选出以“S”开头的城市数据,那么可以:

    SELECT city, max(temp_lo)

    FROM weather

    WHERE city LIKE 'S%' -- LIKE匹配行,在9.7章节进行解释。

    GROUP BY city

    HAVING max(temp_lo) < 40;

    了解聚合与SQL的WHERE和HAVING子句之间的交互非常重要。

     

    WHERE与HAVING之间的本质区别是:where在聚合之前选取行(也就是说,where控制哪些行进入聚合计算。),而having是筛选聚合之后的行。因此,where字句中不能包含聚合函数;使用聚合函数去决定哪些行由聚合函数计算,毫无意义。另一方面,HAVING字句中总是包含聚合函数。(严格来说,HAVING后可以不加聚合函数,但这基本毫无用处。而可以使用where字句更好的满足相应的需求。)

     

    在前面的示例中,我们可以将对城市名称的过滤放到where字句中,这比将对城市名称的过滤放到HAVING字句中更有效率。因为放到where字句中进行过滤,将过滤之后的数据进行聚合计算,从而减少了聚合的计算量。

     

    展开全文
  • Aggregate stuff

    2020-12-01 18:23:33
    <div><p>This is a bunch of small commits that cleanup the aggregate-address code in bgp as well fix the issue where we were sending a update for every prefix change associated with a aggregate ...
  • <div><p>Add ability to query aggregate values and do aggregate joins. In order to support querying aggregate values, a new aggregate query builder would need to be added and included in the database ...
  • Aggregate Attributes

    2020-12-02 23:15:21
    <p>Is there a way to specify explicit attributes in Aggregate. <p>In AggregateBase.js file there is Aggregate object literal which has attributes property. This attributes property has 3 more ...
  • Aggregate Bug

    2020-12-08 21:41:56
    <div><p>Comparing the two sets of code (C# vs JS), the Aggregate functions aren't evaluating in the same way: <p>C# (https://dotnetfiddle.net/57YHxA) <pre><code>var res1 = new object[] { 1, &#...
  • <div><p>Need the rank aggregate (see most databases on how it works). Would be nice to provide extern aggregates. </p><p>该提问来源于开源项目:souffle-lang/souffle</p></div>
  • Aggregate Row

    2020-12-05 07:42:04
    s any capability or workarounds in <code>datagrid</code> for an aggregate row at the bottom of the table? For example, totalling the price in a column of each row on the last row. :)</p><p>该提问来源...
  • Aggregate error

    2020-12-29 00:08:36
    option is required, except for aggregate with the explain argument" at /var/www/html/vendor/doctrine/mongodb/lib/Doctrine/MongoDB/Collection.php</p> 该提问来源于开源项目:doctrine/mongodb...
  • Aggregate occupancy

    2020-12-08 19:20:52
    <p>Would be great if the API could handle this issue, instead of all implementations having to aggregate the sections' prognosis.</p><p>该提问来源于开源项目:OpendataCH/Transport</p></div>
  • Aggregate operations

    2020-12-29 17:52:49
    <div><p>Any plans to provide a different syntax for aggregate operations? The existing APIs aren't very LINQ friendly. <p>Operation | Current API | Better API --- | --- | --- Collect | new ...
  • scala aggregate

    2021-03-29 22:54:36
    scala aggregate函数 不分区 object Test1 { def main(args: Array[String]): Unit = { val ls=List(1,2,3,5) val res: Int = ls.aggregate(10)((x1, x2) => {x1+x2}, (y1, y2) => {y1+y2}) println(res) ...

    scala aggregate函数

    不分区

    object Test1 {
      def main(args: Array[String]): Unit = {
        val ls=List(1,2,3,5)
        val res: Int = ls.aggregate(10)((x1, x2) => {x1+x2}, (y1, y2) => {y1+y2})
        println(res)
      }
    }
    运行结果:21
    

    如下图所示,将初始值10赋值给x1,x2分别取列表中的每个值,与x1进行加运算,结果赋值给x1,由于没有分区,没有第二阶段的combine操作,第一阶段得到的结果就是最终结果

    在这里插入图片描述

    分区

    由于par函数需要考虑机器cpu内核线程的数量,本例是在理想状态下进行说明,即有4个线程同时运行

    object Test1 {
      def main(args: Array[String]): Unit = {
        val ls=List(1,1,1,1)
        val res: Int = ls.par.aggregate(10)((x1, x2) => {x1+x2}, (y1, y2) => {y1+y2})
        println(res)
      }
    }
    运行结果:44
    

    如下图所示,使用了par函数,并行计算aggregate,在本例中,有四个线程并行计算,即初始值10赋值给了4个线程的x1,每个线程的x2分别获取列表中的1,进行阶段一的计算,之后阶段二combine操作用于聚集每个分区的结果

    在这里插入图片描述

    展开全文
  • 聚合 aggregate

    2019-11-01 15:33:07
    聚合 aggregate 聚合(aggregate)主要用于计算数据,类似sql中的sum()、avg() 语法 db.集合名称.aggregate([ {管道 : {表达式}} ]) 管道 管道在Unix和Linux中一般用于将当前命令的输出结果作为下一个命令的...

    聚合 aggregate

    • 聚合(aggregate)主要用于计算数据,类似sql中的sum()、avg()

    • 语法

      db.集合名称.aggregate([ {管道 : {表达式}} ])
      

    管道

    • 管道在Unix和Linux中一般用于将当前命令的输出结果作为下一个命令的输入

      ps aux | grep mongod
      
    • 在mongodb中,管道具有同样的作用,文档处理完毕后,通过管道进行下一次处理

    • 常用管道

      • $group:将集合中的文档分组,可用于统计结果
      • $match:过滤数据,只输出符合条件的文档
      • $project:修改输入文档的结构,如重命名、增加、删除字段、创建计算结果
      • $sort:将输入文档排序后输出
      • $limit:限制聚合管道返回的文档数
      • $skip:跳过指定数量的文档,并返回余下的文档
      • $unwind:将数组类型的字段进行拆分

    表达式

    • 处理输入文档并输出

    • 语法

      表达式:'$列名'
      
    • 常用表达式

      • $sum:计算总和,$sum:1同count表示计数
      • $avg:计算平均值
      • $min:获取最小值
      • $max:获取最大值
      • $push:在结果文档中插入值到一个数组中
      • $first:根据资源文档的排序获取第一个文档数据
      • $last:根据资源文档的排序获取最后一个文档数据
    > db.stu.aggregate([{$group: {_id : "$age", _sum : {$sum : 1}}}])
    { "_id" : 45, "_sum" : 1 }
    { "_id" : 16, "_sum" : 1 }
    { "_id" : 40, "_sum" : 1 }
    { "_id" : 18, "_sum" : 2 }
    { "_id" : 20, "_sum" : 1 }
    

    ——————————————————————————————————————

    $group

    • 将集合中的文档分组,可用于统计结果
    • _id表示分组的依据,使用某个字段的格式为’$字段’
    • 例1:统计男生、女生的总人数
    db.stu.aggregate([
        {$group:
            {
                _id:'$gender',
                counter:{$sum:1}
            }
        }
    ])
    

    Group by null

    • 将集合中所有文档分为一组
    • 例2:求学生总人数、平均年龄
    db.stu.aggregate([
        {$group:
            {
                _id:null,
                counter:{$sum:1},
                avgAge:{$avg:'$age'}
            }
        }
    ])
    

    透视数据

    • 例3:统计学生性别及学生姓名
    db.stu.aggregate([
        {$group:
            {
                _id:'$gender',
                name:{$push:'$name'}
            }
        }
    ])
    
    • 使用$$ROOT可以将文档内容加入到结果集的数组中,代码如下
    db.stu.aggregate([
        {$group:
            {
                _id:'$gender',
                name:{$push:'$$ROOT'}
            }
        }
    ])
    

    $match

    • 用于过滤数据,只输出符合条件的文档
    • 使用MongoDB的标准查询操作
    • 例1:查询年龄大于20的学生
    db.stu.aggregate([
        {$match:{age:{$gt:20}}}
    ])
    
    • 例2:查询年龄大于20的男生、女生人数
    db.stu.aggregate([
        {$match:{age:{$gt:20}}},
        {$group:{_id:'$gender',counter:{$sum:1}}}
    ])
    

    $project

    • 修改输入文档的结构,如重命名、增加、删除字段、创建计算结果
    • 例1:查询学生的姓名、年龄
    db.stu.aggregate([
        {$project:{_id:0,name:1,age:1}}
    ])
    
    • 例2:查询男生、女生人数,输出人数
    db.stu.aggregate([
        {$group:{_id:'$gender',counter:{$sum:1}}},
        {$project:{_id:0,counter:1}}
    ])
    

    $sort

    • 将输入文档排序后输出
    • 例1:查询学生信息,按年龄升序
    b.stu.aggregate([{$sort:{age:1}}])
    
    • 例2:查询男生、女生人数,按人数降序
    db.stu.aggregate([
        {$group:{_id:'$gender',counter:{$sum:1}}},
        {$sort:{counter:-1}}
    ])
    

    $limit

    • 限制聚合管道返回的文档数
    • 例1:查询2条学生信息
    db.stu.aggregate([{$limit:2}])
    

    $skip

    • 跳过指定数量的文档,并返回余下的文档
    • 例2:查询从第3条开始的学生信息
    db.stu.aggregate([{$skip:2}])
    
    • 例3:统计男生、女生人数,按人数升序,取第二条数据
    db.stu.aggregate([
        {$group:{_id:'$gender',counter:{$sum:1}}},
        {$sort:{counter:1}},
        {$skip:1},
        {$limit:1}
    ])
    
    • 注意顺序:先写skip,再写limit

    $unwind

    • 将文档中的某一个数组类型字段拆分成多条,每条包含数组中的一个值

    语法1

    • 对某字段值进行拆分
    db.集合名称.aggregate([{$unwind:'$字段名称'}])
    
    • 构造数据
    db.t2.insert({_id:1,item:'t-shirt',size:['S','M','L']})
    
    • 查询
    db.t2.aggregate([{$unwind:'$size'}])
    

    语法2

    • 对某字段值进行拆分
    • 处理空数组、非数组、无字段、null情况
    db.inventory.aggregate([{
        $unwind:{
            path:'$字段名称',
            preserveNullAndEmptyArrays:<boolean>#防止数据丢失
        }
    }])
    
    • 构造数据
    db.t3.insert([
    { "_id" : 1, "item" : "a", "size": [ "S", "M", "L"] },
    { "_id" : 2, "item" : "b", "size" : [ ] },
    { "_id" : 3, "item" : "c", "size": "M" },
    { "_id" : 4, "item" : "d" },
    { "_id" : 5, "item" : "e", "size" : null }
    ])
    
    • 使用语法1查询
    db.t3.aggregate([{$unwind:'$size'}])
    
    • 查看查询结果,发现对于空数组、无字段、null的文档,都被丢弃了
    • 问:如何能不丢弃呢?
    • 答:使用语法2查询
    db.t3.aggregate([{$unwind:{path:'$sizes',preserveNullAndEmptyArrays:true}}])
    
    展开全文
  • <div><p>Fixed issue of mismatched aggregate types between command and loaded events when rebuilding an aggregate from stored events. Issue surfaces when a command is dispatched with an aggregate id ...
  • Aggregate_WP wordpress模板

    2021-05-27 16:11:57
    Aggregate_WP wordpress模板
  • mongo aggregate

    2016-09-05 11:04:42
    aggregate简单例子
  • MongoDB aggregate

    2018-09-03 10:50:06
    // aggregate里的各种查询可以组合使用 // 聚合查询 Entry.aggregate([ { // $match 筛选,和find查询条件一致 $match: { $or: [{'showcase.type': CONSTANT.contestType.STANDARD}], 'sho...
  • Issues with aggregate

    2020-12-09 08:55:56
    m having an issue with aggregate and this library. The error I get is: <pre><code> TypeError: Cannot read property 'constructor' of undefined </code></pre> <p>However, the aggregate return ...
  • Add aggregate function

    2020-12-27 04:03:52
    aggregate(every: 10m, fns: {max: (r) => max(), min: (r) => min(), mean: (r) => mean()}) aggregate(every: 10m, fns: {max, min, mean, myMean}) aggregate(every: 10m, fns: [max, min, ...
  • 4.2.7. Aggregate Expressions

    2020-12-25 16:45:49
    4.2.7. Aggregate Expressions 4.2.7.聚合表达式 An aggregate expression represents the application of an aggregate function across the rows selectedby a query. An aggregate function reduces multiple ...
  • Feature aggregate refactor

    2020-12-27 21:56:44
    <p>This change combines the similar basic aggregation functions into a single <code>aggregate</code> function. This can be extended to support the new ...
  • Error getting aggregate

    2020-12-02 16:22:45
    <div><p>Is the command <code>aggregate</code> not implemented? <pre><code> com.mongodb.MongoCommandException: Command failed with error 59: 'no such cmd: aggregate' on server localhost:27117. ...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 15,346
精华内容 6,138
关键字:

aggregate