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
2 answers

Switch case in aggregate query

I want to have a switch case in my SQL query such that when the group by does not group any element i dont want to aggregate otherwise I want to. Is that possible. my query is something like this: select count(1),AVG(student_mark) ,case when…
Giselle
  • 23
  • 3
2
votes
2 answers

summarize values on a tree

I used a Tree control to view some hierarchical items base on a nested (parent child) table . Every node has a NameValue format that accept either a name and value . But only Leaves (last nodes) have integer values and values of parents are left…
Mostafa Armandi
  • 879
  • 1
  • 11
  • 24
2
votes
2 answers

nested json aggregated rows on group by in postgresql

I have a postgresql table alok=# select * from people; name | country | city ---------+---------+--------- alok | india | delhi ram | india | kolkata shyam | india | kanpur krishna | us | newyork ajit | india …
Alok
  • 7,734
  • 8
  • 55
  • 100
2
votes
3 answers

Grouping by sequence and then finding minimum value in a column

I have a data set that amoungst other columns has date, sequence and low columns, please see df below. The sequence from 1-to-9 is considered one block or one full cycle in the sequence column The data set has several such complete block/cycles and…
cephalopod
  • 1,826
  • 22
  • 31
2
votes
1 answer

MongoDB complex aggregation

I have documents with the following structure in my database: { "reading_ts": ISODate(...), "points": 2.3, "user_id": 2 } I will have more documents like this for each user_id per day...millions of them... I would like to implement the…
tatulea
  • 113
  • 1
  • 10
2
votes
2 answers

Aggregate root invariant enforcement with application quotas

The application Im working on needs to enforce the following rules (among others): We cannot register a new user to the system if the active user quota for the tenant is exceeded. We cannot make a new project if the project quota for the tenant is…
2
votes
2 answers

get the sum of one column and average of the other with grouping

I have a dataframe which looks like this: Year Iteration Production Technology 2015 1 200 Gas 2015 1 305 Gas 2016 1 150 Gas 2016 1 200 Gas 2015 2 200 …
Henkpenk
  • 37
  • 6
2
votes
2 answers

aggregate (R) behaving differently for apparently identical tasks

I've been banging my head against a brick wall for days on this issue; I wonder if anyone can see what is wrong with my code, or tell me if I am overlooking something obvious. I have this data.frame, where most columns are vectors, either numerical…
user6376297
  • 575
  • 2
  • 15
2
votes
0 answers

new Date() in MongoDB aggregate returns 1970-01-01T00:00:00Z

I'm trying to see if a date is in the past in a Mongo aggregate pipeline, using Meteor / nodeJS. The pipeline has to be completely self-contained; I cannot pre-calculate any values. The first step is to find the current date. According to the docs,…
Little Brain
  • 2,647
  • 1
  • 30
  • 54
2
votes
1 answer

Grouping by multiple dimensions, summarise and add calculated column

I have this df: boxChange sameCat # C1 > C2 TRUE # C1 > C2 TRUE # A0 > A1 TRUE # A1 > E4 FALSE # C3 > E6 FALSE # E0 > E3 TRUE # ... ... I would like to group by both columns, count the occurrences and arrange by…
tuspazio
  • 213
  • 3
  • 9
2
votes
1 answer

Aggregating neighboring rows with partitioning

I have a huge data set on MS SQL 2012 where a special aggregation must be done. Here is an example of dataset. Key PartitionID StartTime Duration Name 1 1 23/05/2019 18:18:28.125 1 X 2 1 …
2
votes
3 answers

Add every three rows of data frame and them multiply the new results - R

I have a data frame and I would like to add every three rows of it. Then, to apply cumprod to the rows in order to have a new data.frame with the resulting new rows. At the end I will have only one third of the number of rows. Below you can find…
Yesid
  • 125
  • 5
2
votes
1 answer

R - aggregated data.table columns differently

I am given a large data-table that needs to be aggregated according to the first column: The problem is the following: For several columns, one just has to form the sum for each category (given in column 1) For other columns, one has to calculate…
Strickland
  • 590
  • 4
  • 14
2
votes
1 answer

Spring MongoDB Aggregation Group - Can't get the group query right

I have a document in a MongoDB, which looks like follows. { "_id" : ObjectId("5ceb812b3ec6d22cb94c82ca"), "key" : "KEYCODE001", "values" : [ { "classId" : "CLASS_01", "objects" : [ { …
Romeo Sierra
  • 1,666
  • 1
  • 17
  • 35
2
votes
0 answers

Sum totals in new columns per period range SQL

I am trying to summarize total per multiple period range and display them in new columns. I have done simple sum function in sql but only based on one date range. Now I would like to show sums of totals per various date ranges. To be honest, I…
zofia
  • 91
  • 1
  • 1
  • 3