Questions tagged [aggregate]

Aggregate refers to the process of summarizing grouped data, commonly used in Statistics.

Aggregate refers to the process of summarizing grouped data, commonly used in Statistics. Typically this involves replacing groups of data with single values (e.g. sum, mean, standard deviation, etc.). In SQL databases and data manipulation libraries such as in , this is accomplished with the use of GROUP BY and aggregate functions.

Documentation:

8256 questions
2
votes
3 answers

R: Sum each column by subgroup

I have a matrix of plant species occurrence data. The matrix is set up so that every column is a species, and every row is a sampling location. I also have identifiers that group sampling locations based on certain environmental variables. I would…
Isaac
  • 59
  • 1
  • 6
2
votes
1 answer

Find min and max value from the array in mongodb

I have Following Project Collection Project Collection : [ { Id : 1, name : p1, tasks : [{ taskId : t1, startDate : ISODate("2018-09-24T10:02:49.403Z"), endDate : ISODate("2018-09-26T10:02:49.403Z"), }, …
2
votes
2 answers

Completing calculations in temp table and returning those results in a second query

Fiddle - http://sqlfiddle.com/#!18/c2b80/17 Tables: CREATE TABLE [OrderTable] ( [id] int, [OrderGroupID] int, [Total] int, [fkPerson] int, [fkitem] int PRIMARY KEY (id) ) INSERT INTO [OrderTable] (id, OrderGroupID, Total…
Ryan Gadsdon
  • 2,272
  • 4
  • 31
  • 56
2
votes
1 answer

How to aggregate the sum of a field to a string_Aggregated value Postgres

The query below shows me a list of students with their basic info. I wanted to aggregate the sum of boys and girls without having to display seperate columns for them. So I created 2 columns, and I took their final sum and displayed it in the final…
Tito
  • 601
  • 8
  • 23
2
votes
1 answer

mongodb aggregation for finding recent data

I have a model which looks like { "_id" : ObjectId("5b975b7ffb8361fa0cdacc41"), "refid" : 1, "item" : "xyz1", "qnid" : 1 } { "_id" : ObjectId("5b975b7ffb8361fa0cdacc42"), "refid" : 1, "item" : "xyz2", "qnid" : 2 } { "_id" :…
2
votes
1 answer

Aggregate based on each item in a special character seperated column in Pandas

I have input data as given below Date Investment Type Medium 1/1/2000 Mutual Fund, Stocks, Fixed Deposit, Real Estate Own, Online,Through Agent 1/2/2000 Mutual Fund, Stocks, Real Estate …
Sid
  • 552
  • 6
  • 21
2
votes
1 answer

How to perform GroupBy Sum query on a list?

Background I have worked with C#.Net + LINQ wherever possible and trying my hand at C++ development for a project I am involved. Of course, I fully realize that C# and C++ are two different worlds. Question I have an std::list where T is a struct…
raidensan
  • 1,099
  • 13
  • 31
2
votes
2 answers

Calculate median for multiple columns by group based on subsets defined by other columns

I am trying to calculate the median (but that could be substituted by similar metrics) by group for multiple columns based on subsets defined by other columns. This is direct follow-on question from this previous post of mine. I have attempted to…
M.Teich
  • 575
  • 5
  • 22
2
votes
1 answer

SQL Server - Count Distinct outside of group

Suppose I have the following table in my SQL Server (2012) DB: Tbl1: Id1: Id2: Date: Value: 1 A '2018-01-01' 1 1 B '2018-01-01' 1 1 C '2018-01-01' 1 1 A …
John Bustos
  • 19,036
  • 17
  • 89
  • 151
2
votes
2 answers

Sum json objects in SQL

How do I merge rows and sum JSON objects in SQL? Given the following table, I want to merege rows by UserId and combine JSON objects.Considering that the JSON key is unknown in advance. Id UserId Platforms …
Leila
  • 57
  • 1
  • 7
2
votes
1 answer

How to add a new field in mongodb aggregate from calculation of any of array items

I'm struggling to find out how to add a new status field in an aggregate based on a calculation of an array of items. Currently, I do this in Angular front-end by asking both collections and iterating each element with the _.some() method of Lodash.…
2
votes
2 answers

mongodb aggregation $max and corresponding timestamp

I'm being challenged by the $group $max in an aggregation with MongoDB on Nodes Express app. Here is the a sample of the…
PappyG
  • 21
  • 1
2
votes
4 answers

Select rows by ID with most matches

I have a data frame like this: df <- data.frame(id = c(1,1,1,2,2,3,3,3,3,4,4,4), torre = c("a","a","b","d","a","q","t","q","g","a","b","c")) and I would like my code to select for each id the torre that repeats more, or the last…
2
votes
1 answer

Can't get aggregate() work for regression by group

I want to use aggregate with this custom function: #linear regression f-n CalculateLinRegrDiff = function (sample){ fit <- lm(value~ date, data = sample) diff(range(fit$fitted)) } dataset2 = aggregate(value ~ id + col, dataset,…
Nata
  • 171
  • 3
  • 15
2
votes
1 answer

Getting subdocuments using $lookup

I want to get the subdocuments from another collection using $lookup but it doesn't work. Currently brain dead... I have a collection for Transactions example transaction { type: 'PURCHASE', // but it can be something else also eg ORDER …
webmaster
  • 1,960
  • 24
  • 29
1 2 3
99
100