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
44
votes
4 answers

Performing a query on a result from another query?

I have a the query: SELECT availables.bookdate AS Date, DATEDIFF(now(),availables.updated_at) as Age FROM availables INNER JOIN rooms ON availables.room_id=rooms.id WHERE availables.bookdate BETWEEN '2009-06-25' AND date_add('2009-06-25', INTERVAL 4…
holden
  • 13,471
  • 22
  • 98
  • 160
44
votes
1 answer

Use data.table to count and aggregate / summarize a column

I want to count and aggregate(sum) a column in a data.table, and couldn't find the most efficient way to do this. This seems to be close to what I want R summarizing multiple columns with data.table. My data: set.seed(321) dat <- data.table(MNTH =…
Whitebeard
  • 5,945
  • 5
  • 24
  • 31
43
votes
2 answers

SELECT list is not in GROUP BY clause and contains nonaggregated column

Receiving the following error: Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'world.country.Code' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with…
Danny J. Williams
  • 431
  • 1
  • 4
  • 3
43
votes
1 answer

How to get an Elasticsearch aggregation with multiple fields

I'm attempting to find related tags to the one currently being viewed. Every document in our index is tagged. Each tag is formed of two parts - an ID and text name: { ... meta: { ... tags: [ { id:…
i_like_robots
  • 2,760
  • 2
  • 19
  • 23
43
votes
1 answer

SQL Server "cannot perform an aggregate function on an expression containing an aggregate or a subquery", but Sybase can

This issue has been discussed before, but none of the answers address my specific problem because I am dealing with different where clauses in the inner and outer selects. This query executed just fine under Sybase, but gives the error in the title…
PillowMetal
  • 735
  • 1
  • 7
  • 14
42
votes
4 answers

Repository Pattern: how to Lazy Load? or, Should I split this Aggregate?

I have a domain model that has the concept of an Editor and a Project. An Editor owns a number of Projects, and a Project has not only an Editor owner, but also a number of Editor members. Therefore, an Editor also has a number of "joined"…
41
votes
2 answers

Summarizing by subgroup percentage in R

I have a dataset like this: df = data.frame(group = c(rep('A',4), rep('B',3)), subgroup = c('a', 'b', 'c', 'd', 'a', 'b', 'c'), value = c(1,4,2,1,1,2,3)) group | subgroup | value ------------------------ A | …
oliver13
  • 996
  • 2
  • 7
  • 19
40
votes
5 answers

AggregateException C# example

I have seen an example of AggregateException on the web and I'm trying to figure out how it works. I have written a simple example, but my code for some reason doesn't work. Could someone explain to me what the problem is? public static void…
Dan
  • 403
  • 1
  • 4
  • 4
39
votes
2 answers

Designated initializers in C++20

I've got a question about one of the c++20 feature, designated initializers (more info about this feature here) #include constexpr unsigned DEFAULT_SALARY {10000}; struct Person { std::string name{}; std::string surname{}; …
MateuszGierczak
  • 398
  • 1
  • 4
  • 10
39
votes
4 answers

Calculating the averages for each KEY in a Pairwise (K,V) RDD in Spark with Python

I want to share this particular Apache Spark with Python solution because documentation for it is quite poor. I wanted to calculate the average value of K/V pairs (stored in a Pairwise RDD), by KEY. Here is what the sample data looks like: >>>…
NYCeyes
  • 5,215
  • 6
  • 57
  • 64
38
votes
2 answers

Aggregate vs Sum Performance in LINQ

Three different implementations of finding the sum of an IEnumerable < int> source are given below along with the time taken when the source has 10,000 integers. source.Aggregate(0, (result, element) => result + element); takes 3 ms source.Sum(c…
Gopal
  • 1,372
  • 2
  • 16
  • 32
37
votes
7 answers

Does COUNT(*) always return a result?

If I run a query such as: SELECT COUNT(*) as num FROM table WHERE x = 'y' Will it always return a result, even when the query doesn't match any record? Or do I need to validate and make sure a row is returned as the result?
Ali
  • 261,656
  • 265
  • 575
  • 769
34
votes
7 answers

What Belongs to the Aggregate Root

This is a practical Domain Driven Design question: Conceptually, I think I get Aggregate roots until I go to define one. I have an Employee entity, which has surfaced as an Aggregate root. In the Business, some employees can have work-related…
jlembke
  • 13,217
  • 11
  • 42
  • 56
33
votes
5 answers

Using Enumerable.Aggregate(...) Method over an empty sequence

I would like to use the Enumerable.Aggregate(...) method to concatenate a list of strings separated by a semicolon. Rather easy, isn't it? Considering the following: private const string LISTSEPARATOR = "; "; album.OrderedTracks is…
lorcan
  • 359
  • 1
  • 3
  • 4
33
votes
6 answers

Sql Server : How to use an aggregate function like MAX in a WHERE clause

I want get the maximum value for this record. Please help me: SELECT rest.field1 FROM mastertable AS m INNER JOIN ( SELECT t1.field1 field1, t2.field2 FROM table1 AS T1 INNER JOIN table2 AS…
Geetha