aggregate

How to get top 3 frequencies in MySQL?

Hello, In MySQL I have a table called "meanings" with three columns: "person" (int), "word" (byte, 16 possible values) "meaning" (byte, 26 possible values). A person assigns one or more meanings to each word: person word meaning ------------------- 1 1 4 1 2 19 1 2 7 <-- Note: second meaning for word 2 1 ...

Concatenation of fields in different rows

I'm stuck on an aggregation problem that I can't get to the bottom of. I have some data which is best summarized as follows id |phraseId|seqNum|word ========================= 1 |1 |1 |hello 2 |1 |2 |world 3 |2 |1 |black 4 |2 |2 |and 5 |2 |3 |white I'd like a query that gives back...

DDD and distinction between Entity and Value object. Choosing the aggregate root

I am design and EMR. I have determined the central object to the domain is the Patient. The patient must have the following a Doctor and Medical Records. Medical Records is a grouping term refering to the collective of Encounters, Labs, XRays, Prescriptions.... I am new to DDD and I am having trouble with a couple of concepts and my...

HOW-TO Include movie showtimes in Google Movies

I am making the website of a movie theater, and I want Google Movies to index the showtimes I publish on the website. Does anyone know if there's a way to do this?, maybe using microformats? or exposing this information using RSS or something similar?. Thx ...

T-SQL query and group by reporting help

So I have some data that looks like this. `USERID1 USERID2` 1 10 2 20 2 30 3 40 3 50 1 10 2 20 2 30 3 50 I want a query that produces the following `USERID1 COUNT` 2 2 3 2 It's a group by query that shows me ...

Group and Concatenation aggregate to produce binary string SQL

Scenario: I have a table that is used for storing a user's security on different PO series. And currently selecting a user's security produces the following record set. each permission column has a boolean value and i would like to group each set on Job, SubJobNum and get a binary result (string if need be) that would result in the fo...

Aggregate Pattern and Performance Issues

Hello, I have read about the Aggregate Pattern but I'm confused about something here. The pattern states that all the objects belonging to the aggregate should be accessed via the Aggregate Root, and not directly. And I'm assuming that is the reason why they say you should have a single Repository per Aggregate. But I think this ad...

Sumproduct using Django's aggregation

Question Is it possible using Django's aggregation capabilities to calculate a sumproduct? Background I am modeling an invoice, which can contain multiple items. The many-to-many relationship between the Invoice and Item models is handled through the InvoiceItem intermediary table. The total amount of the invoice—amount_invoiced—i...

Can an interface be implemented across an aggregate/composite class in vb.net?

VB.NET .NET 3.5 I have an aggregate class called Package as part of a shipping system. Package contains another class, BoxType . BoxType contains information about the box used to ship the package, such as length, width, etc. of the Box. Package has a method called GetShippingRates. This method calls a separate helper class, ShipRat...

ORM Persistence by Reachability violates Aggregate Root Boundaries?

Most common ORMs implement persistence by reachability, either as the default object graph change tracking mechanism or an optional. Persistence by reachability means the ORM will check the aggregate roots object graph and determines wether any objects are (also indirectly) reachable that are not stored inside it's identity map (Linq2Sq...

DDD: Aggregate Roots

Hello, 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 PlannedRole and PlannedTraining do not make sense out of the context of a Plan. The...

Django ORM: Ordering w/ aggregate functions — None special treatment

Hi, I'm doing query like that: SomeObject.objects.annotate(something=Avg('something')).order_by(something).all() Now, I normally have an aggregate field in my model that I use with Django signals to keep in sync, however in this case perfomance isn't an issue so I thought I'd keep it simple and just use subqueries. This approach, h...

Create a user-defined aggregate without SQL CLR

I am planning on deploying a database to SQL Azure, so I cannot use the SQL CLR. However, I have a need to create an aggregate function -- in my case, I need to STUnion a bunch of Geography objects together. (Azure is expected to support Spatial by June.) Is there another way to accomplish this, without making use of the CLR, in a query...

DDD: Persisting aggregates

Hello, Let's consider the typical Order and OrderItem example. Assuming that OrderItem is part of the Order Aggregate, it an only be added via Order. So, to add a new OrderItem to an Order, we have to load the entire Aggregate via Repository, add a new item to the Order object and persist the entire Aggregate again. This seems to hav...

Mysql - Grouping the result based on a mathematical operation and SUM() function

Hi all... I'm having the following two tables... Table : room_type type_id type_name no_of_rooms max_guests rate 1 Type 1 15 2 1254 2 Type 2 10 1 3025 Table : reservation reservation_id start_date end_date room_type booked_rooms ...

TSQL: finding unique entries in a single table

Consider a table or CTE structured like this: Name Num ---- ---- Abc 12 Abc 12 XYZ 70 XYZ 80 XYZ 85 Bar 50 Bar 55 Foo 44 Foo 44 Baz 88 The requirement is to determine the Name where multiple different Nums exist. The desired resultset is Name ---- XYZ Bar What TSQL stateme...

SQL statement HAVING MAX(some+thing)=some+thing

I'm having trouble with Microsoft Access 2003, it's complaining about this statement: select cardnr from change where year(date)<2009 group by cardnr having max(time+date) = (time+date) and cardto='VIP' What I want to do is, for every distinct cardnr in the table change, to find the row with the latest (time+date) that is before year...

Organizing multi level aggregate object or composite

Hye! I have Aggregate object that have more than one level. Aggregate root is Network object and it have collection of Nodes and Links. Node and Link have collection of Segments, and Segment have collection of Lanes. My domain is traffic network and this is only part of this aggregate: public class Network { private List<Node> nodes; ...

Is it ok to call specifications from an aggregate factory for validation, or does that validation call belong in a unit test (DDD)?

I have created a factory and a set of specifications to create and validate an aggregate root. Currently I have some tests for the factory that call the specifications on the product of the factory, but I'm wondering if that's enough. It might be better from a design perspective to couple the factory to the specifications of it's produ...

Linq TakeWhile depending on sum (or aggregate) of elements

I have a list of elements and want to takeWhile the sum (or any aggregation of the elements) satisfy a certain condition. The following code does the job, but i am pretty sure this is not an unusual problem for which a proper pattern should exist. var list = new List<int> { 1, 2, 3, 4, 5, 6, 7 }; int tmp = 0; var listWithSum = from x i...