({{, (RefLink[AggregatedEntityClass, paclet:ref/AggregatedEntityClass])[class,"prop"->f] 
represents an entity class containing a single entity with the property prop whose value is the result of applying the function f to the whole specified entity class.}, {, (RefLink[AggregatedEntityClass, paclet:ref/AggregatedEntityClass])[class,{"(Subscript[prop, 1])"->(Subscript[f, 1]),"(Subscript[prop, 2])"->(Subscript[f, 2]),…}]
constructs multiple properties (Subscript[prop, i]) obtained by applying (Subscript[f, i]) to class.}, {, (RefLink[AggregatedEntityClass, paclet:ref/AggregatedEntityClass])[class,propspec,gprop]
forms groups of elements of class according to their values of the property gprop, then generates an entity class with an entity for each of these groups. }, {, (RefLink[AggregatedEntityClass, paclet:ref/AggregatedEntityClass])[class,propspec,"pname"->f]
forms groups according to the values obtained by applying the entity function f, with the resulting property named pname.}, {, (RefLink[AggregatedEntityClass, paclet:ref/AggregatedEntityClass])[class,propspec,{(Subscript[gspec, 1]),(Subscript[gspec, 2]),…}]
forms groups for which the set of values defined by the (Subscript[gspec, i]) is distinct. }})

OpenersNotesSection(Spacer1)Details

In (RefLink[AggregatedEntityClass, paclet:ref/AggregatedEntityClass])[class,"prop"->f], the function f can either be an (RefLink[EntityFunction, paclet:ref/EntityFunction])[…] object or a function fun that will be treated as (RefLink[EntityFunction, paclet:ref/EntityFunction])[x,fun[x["prop"]]].

In (RefLink[AggregatedEntityClass, paclet:ref/AggregatedEntityClass])[class,propspec], (RefLink[EntityFunction, paclet:ref/EntityFunction]) objects in propspec are in effect applied to an association of properties whose values are the list of values for the entities in class.

(RefLink[EntityFunction, paclet:ref/EntityFunction]) expressions appearing in the second argument of (RefLink[AggregatedEntityClass, paclet:ref/AggregatedEntityClass]) are not applied to single entities in the first argument, but rather to the whole first argument, if no third argument is present, or to the entity classes obtained by grouping according to the third argument.

(RefLink[EntityFunction, paclet:ref/EntityFunction]) expressions appearing in the third argument of (RefLink[AggregatedEntityClass, paclet:ref/AggregatedEntityClass]) are applied separately to the individual entities in the first argument.

Unlike (RefLink[GroupBy, paclet:ref/GroupBy]), (RefLink[AggregatedEntityClass, paclet:ref/AggregatedEntityClass])[class,propspec,{(Subscript[prop, 1]),(Subscript[prop, 2]),…}] does not perform hierarchical grouping if its third argument is a list; rather, it will create a class with a number of entities given by the distinct values of (RefLink[EntityValue, paclet:ref/EntityValue])[class,{(Subscript[prop, 1]),(Subscript[prop, 2]),…}].

(RefLink[EntityProperties, paclet:ref/EntityProperties])[AggregatedEntityClass[class,{"(Subscript[name, 1])"->(Subscript[entityfunc, 1]),"(Subscript[name, 2])"->(Subscript[entityfunc, 2]),…},{"(Subscript[prop, 1])","(Subscript[prop, 2])",…}]] returns {(RefLink[EntityProperty, paclet:ref/EntityProperty])[agg,"(Subscript[name, 1])"],(RefLink[EntityProperty, paclet:ref/EntityProperty])[agg,"(Subscript[name, 2])"],…,(RefLink[EntityProperty, paclet:ref/EntityProperty])[agg,"(Subscript[prop, 1])"],(RefLink[EntityProperty, paclet:ref/EntityProperty])[agg,"(Subscript[prop, 2])"],…} where agg is the whole (RefLink[AggregatedEntityClass, paclet:ref/AggregatedEntityClass]) expression.

OpenersPrimaryExamplesSection(Spacer1)Examples  (7)

OpenersExampleSection0(Spacer1)Basic Examples  (3)

Create an aggregation of all countries and compute their total area:

AggregatedEntityClass["Country", "TotalArea"->EntityFunction[e,Total[e["Area"]]]]["TotalArea"]

An equivalent computation, suitable for small datasets:

Total[EntityValue["Country","Area"]]

Find the mean atomic mass for elements in each period class:

AggregatedEntityClass["Element", "AtomicMass" -> Mean, "Period"]["AtomicMass"]

When used with relational-database-backed entities, a two-argument (RefLink[AggregatedEntityClass, paclet:ref/AggregatedEntityClass]) corresponds to using aggregate functions in the SELECT statement:

EntityRegister[EntityStore[RelationalDatabase[FindFile["ExampleData/ecommerce-database.sqlite"]]]]

Compute the total amount of payments:

AggregatedEntityClass["payments","amount"-> Total]["amount"]

Compute the maximum credit limit by country (similar to a GROUP BY statement in SQL languages):

AggregatedEntityClass["customers", "creditLimit" -> Max, "country"][{"country","creditLimit"}]

OpenersExampleSection1(Spacer1)Scope  (2)

The third argument can be an (RefLink[EntityFunction, paclet:ref/EntityFunction]):

AggregatedEntityClass["Country", "MeanArea"->EntityFunction[e,Mean[e["Area"]]],"RoundedPopulation"-> EntityFunction[c,Round[c["Population"],100000000]]][{"RoundedPopulation","MeanArea"}]

Apply a function to the result, typically an aggregation function:

AggregatedEntityClass[LinguisticAssistant, "AggregatedPopulation"->EntityFunction[e,f[e[(EntityProperty["population", EntityProperty["Country","Population"], "EntityProperty[\"Country\", \"Population\"]"])]]]]["AggregatedPopulation"]

Use this to compute the mean value of the result:

AggregatedEntityClass[LinguisticAssistant, "MeanPopulation"->EntityFunction[e,Mean[e[(EntityProperty["population", EntityProperty["Country","Population"], "EntityProperty[\"Country\", \"Population\"]"])]]]]["MeanPopulation"]//N

Or create a pie chart with the result:

AggregatedEntityClass[LinguisticAssistant, "PopulationChart"->EntityFunction[e,PieChart[e[(EntityProperty["population", EntityProperty["Country","Population"], "EntityProperty[\"Country\", \"Population\"]"])]]]]["PopulationChart"]

OpenersExampleSection3(Spacer1)Properties & Relations  (2)

(RefLink[AggregatedEntityClass, paclet:ref/AggregatedEntityClass]) generates entities that correspond to groups:

EntityList[AggregatedEntityClass["Element", "AtomicNumber" -> Mean, "Period"]]

Single entities obtained from (RefLink[AggregatedEntityClass, paclet:ref/AggregatedEntityClass]) effectively correspond to implicit entities:

Entity["Food",
{
(EntityProperty["food type", EntityProperty["Food","FoodType"], "EntityProperty[\"Food\", \"FoodType\"]"])->ContainsExactly[{(Entity["ice cream", Entity["FoodType","IceCream"], "Entity[\"FoodType\", \"IceCream\"]", "food type"])}],(EntityProperty["added food types", EntityProperty["Food","AddedFoodTypes"], "EntityProperty[\"Food\", \"AddedFoodTypes\"]"])->ContainsExactly[{}],(EntityProperty["flavor", EntityProperty["Food","Flavor"], "EntityProperty[\"Food\", \"Flavor\"]"])->(Entity["chocolate", Entity["FoodFlavor","Chocolate"], "Entity[\"FoodFlavor\", \"Chocolate\"]", "flavor"])
}
]["RelativeTotalCaloriesContent"]

AggregatedEntityClass[EntityClass["Food",{EntityProperty["Food","FoodType"]->ContainsExactly[{Entity["FoodType","IceCream"]}],EntityProperty["Food","AddedFoodTypes"]->ContainsExactly[{}],EntityProperty["Food","Flavor"]->Entity["FoodFlavor","Chocolate"]}], "RelativeTotalCaloriesContent" -> Mean]["RelativeTotalCaloriesContent"]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[EntityValue, paclet:ref/EntityValue])  ▪  (RefLink[EntityStore, paclet:ref/EntityStore])  ▪  (RefLink[GroupBy, paclet:ref/GroupBy])  ▪  (RefLink[GatherBy, paclet:ref/GatherBy])  ▪  (RefLink[Merge, paclet:ref/Merge])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Working with Information in Relational Databases, paclet:guide/WorkingWithRelationalDatabases])}, {▪(RefLinkPlain[Database Connectivity, paclet:guide/DatabaseConnectivity])}, {▪(RefLinkPlain[Knowledge Representation & Access, paclet:guide/KnowledgeRepresentationAndAccess])}})}})