@@ -28,6 +28,15 @@ TutorialD is strongly-typed. The basic built-in types are:
2828
2929With regards to boolean values, be sure not to conflate ```t``` or ```f``` as a boolean value with ```true``` and ```false``` which are relation variables.
3030
31+Project:M36 will complain loudly if the expected types do not match. Automatic type coercion does not exist.
32+
33+```
34+TutorialD (master): :showexpr S:{more:=add(10,@SNAME)}
35+ERR: AtomFunctionTypeError "add" 2 IntAtomType StringAtomType
36+```
37+
38+The integer "10" cannot be added to the string SNAME value.
39+
3140### Using Relation Variables
3241
3342Relation Variables are named cells which reference relations within a transaction state. The relation can be replaced with another relation through assignment.
@@ -429,3 +438,41 @@ TutorialD (master): constraint S_status_less_than_50 (S where ^lt(50,@STATUS)){}
429438This expression ensures that the relation variable's relation can never include a tuple with STATUS greater than 50.
430439
431440## Aggregate Queries
441+
442+Aggregate queries in TutorialD are able to provide much more information than SQL queries due to the support for relation-valued attributes. For example, a single query can return aggregate results alongside its constituent tuples.
443+
444+SQL supports aggregate queries using aggregate functions (SUM(), COUNT(), AVERAGE(), etc.) and GROUP BY while the aggregate functions in the relational algebra simply accept relation values as arguments.
445+
446+```
447+TutorialD (master): :showexpr S group ({S#,SNAME,STATUS} as subrel):{citycount:=count(@subrel)}
448+┌──────┬─────────┬─────────────────┐
449+│CITY │citycount│subrel │
450+├──────┼─────────┼─────────────────┤
451+│Paris │2 │┌──┬─────┬──────┐│
452+│ │ ││S#│SNAME│STATUS││
453+│ │ │├──┼─────┼──────┤│
454+│ │ ││S3│Blake│30 ││
455+│ │ ││S2│Jones│10 ││
456+│ │ │└──┴─────┴──────┘│
457+│London│2 │┌──┬─────┬──────┐│
458+│ │ ││S#│SNAME│STATUS││
459+│ │ │├──┼─────┼──────┤│
460+│ │ ││S1│Smith│20 ││
461+│ │ ││S4│Clark│20 ││
462+│ │ │└──┴─────┴──────┘│
463+│Athens│1 │┌──┬─────┬──────┐│
464+│ │ ││S#│SNAME│STATUS││
465+│ │ │├──┼─────┼──────┤│
466+│ │ ││S5│Adams│30 ││
467+│ │ │└──┴─────┴──────┘│
468+└──────┴─────────┴─────────────────┘
469+```
470+
471+In this query result, we can simultaneously answer how many suppliers are located in each city and which suppliers they are. The expression is constructed by first grouping to isolate the city, then extending the query to add a attribute containing the tuple count for each subrelation.
472+
473+|Function Name|Description|
474+|-|-|
475+|count(relation{any tuple types})|return the number of tuples in each relation value|
476+|sum(relation{int})|return the int sum of the relation's values|
477+|max(relation{int})|return the maximum int from all the relation's values|
478+|min(relation{int})|return the minimum int from all the relation's values|