Questions tagged [aggregates]

Aggregate functions, typically found in SQL, derive summary values from multiple rows in a single column.

An aggregate, more commonly known as an aggregate function, is a means to examine the values found in multiple rows from a single column. These are grouped together as input on certain criteria to form a single value of more significant meaning or measurement, such as a set, a bag or a list. Aggregates are usually found in SQL.

179 questions
15
votes
2 answers

Why are repositories only used for aggregates in Domain-Driven Design?

In DDD, repositories are used to perform serialization and de-serialization of aggregates, e.g. by reading and writing to a database. That way, aggregates can contain purer business logic, and won't be coupled to non-domain-specific persistence…
12
votes
3 answers

Domain Driven Design - Aggregate Roots

I'm struggling with aggregates and aggregate roots. I have a natural aggregate root which works for about 60% of the user requests. I.e. those requests naturally apply to the aggregate root. Within my aggregate I have another entity which can only…
ng5000
  • 12,330
  • 10
  • 51
  • 64
7
votes
2 answers

PostgreSQL Aggregates with Multiple Parameters

I've been trying to wrap my head around creating aggregates in PostgreSQL (either 8.4 or 9.1) that accept one or more option parameters. An example would be creating a PL/R extension to compute the p-th quantile, with 0 <= p <= 1. This would look…
7
votes
3 answers

Collect all "minimum" solutions from a predicate

Given the following facts in a database: foo(a, 3). foo(b, 2). foo(c, 4). foo(d, 3). foo(e, 2). foo(f, 6). foo(g, 3). foo(h, 2). I want to collect all first arguments that have the smallest second argument, plus the value of the second argument.…
user1812457
6
votes
3 answers

Conditional JOIN based on column value

I've looked all over, and unfortunately, I can't seem to figure out what I'm doing wrong. I'm developing a personal financial management application that uses a MySQL server. For this problem, I have 4 tables I'm working with. The TRANSACTIONS table…
cameron
  • 65
  • 1
  • 1
  • 5
6
votes
3 answers

How can I "specify a dataset aggregate" in this SSRS Expression?

I need a row value in my SSRS report that is a calculated one based on a couple of fields that are already being used in the report. I want it to display in the textbox named 'textboxPercentageValue'. In semi-plain English, the expression/formula…
B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862
6
votes
1 answer

Aggregates in Nest (ElasticSearch) on child/nested objects

I have a catalog of products that I want to calculate aggregates on. This is simple enough for top level properties such as brand name, manufacturer, etc. The trouble comes with trying to calculate range counts on prices because we sell in…
Jackson Murph
  • 63
  • 1
  • 5
6
votes
3 answers

DDD: Aggregate Roots

I need help with finding my aggregate root and boundary. I have 3 Entities: Plan, PlannedRole and PlannedTraining. Each Plan can include many PlannedRoles and PlannedTrainings. Solution 1: At first I thought Plan is the aggregate root because…
Mosh
  • 5,944
  • 4
  • 39
  • 44
5
votes
1 answer

Repository pattern aggregate and aggregate root with Entity Framework 4.0

I have a question on implementing the repository pattern with my data model. I have searched online and looked into a lot of posts but I do not find any answer which clears my doubts. Basically our domain model goes like below we have a client…
5
votes
2 answers

conditional group by in Oracle

I'm trying to write a query to get the sum of a table with condition. for example this table area | machine | status | qty 1 | machine1 | inprocess | 210 1 | machine2 | pending | 120 1 | …
chip
  • 3,039
  • 5
  • 35
  • 59
5
votes
2 answers

Django - Count a subset of related models - Need to annotate count of active Coupons for each Item

I have a Coupon model that has some fields to define if it is active, and a custom manager which returns only live coupons. Coupon has an FK to Item. In a query on Item, I'm trying to annotate the number of active coupons available. However, the…
Chris Lawlor
  • 47,306
  • 11
  • 48
  • 68
5
votes
2 answers

"Invalid use of aggregating function in this context" in a SET query (Neo4j)

I wonder why this is considered an invalid use of aggregate functions in Neo4j's Cypher: MATCH (p:Project)-[:EMPLOYS]-(n:Person) SET p.youngest = MIN(n.age); While the following is considered a valid use case: MATCH…
retrography
  • 6,302
  • 3
  • 22
  • 32
5
votes
3 answers

How do I ensure consistency of aggregates with high availability?

My team needs to find a solution to the following problem: Our application allows users to view total sales for the enterprise, totals by product, totals by region, totals by region x product, totals by regions x division, etc. You get the idea.…
RonR
  • 298
  • 1
  • 13
5
votes
3 answers

Linq - calculate multiple averages in one query

I'm trying to convert some SQL queries into Linq to avoid multiple trips to the database. The old SQL I'm trying to convert does: SELECT AVG(CAST(DATEDIFF(ms, A.CreatedDate, B.CompletedDate) AS decimal(15,4))), AVG(CAST(DATEDIFF(ms,…
Graham Clark
  • 12,886
  • 8
  • 50
  • 82
4
votes
1 answer

postgres aggregate performance

I've been noticing some problems with simple aggregate performance in Postgres (8.3). The issue is that if I have a table (say 200M rows) that is unique by (customer_id,order_id), then the query select customer_id,max(order_id) from larger_table…
ryan
  • 85
  • 4
1
2 3
11 12