Grouping

One of the most powerful and time saving features of the SDQL is query grouping. There are three ways to instantiate a query grouping:
  1. implicitly by using a parameter without a restricting condition,
  2. explicitly by using a comma-delimited set of conditions, and
  3. with a comma-delimited summative argument.

implicit

An implicit grouping is instantiated when a conditional term is not restricted.

To see the average number of three pointers made for each NBA team in 2015 use the SDQL:
Average(three pointers made) @ team and season=2015

Since the team parameter is not restricted to any value, each value occurring in the database is returned.

To see the average number of three pointers made for the Lakers in each season of the database use the SDQL:
Average(three pointers made) @ team=Lakers and season

explicit

An explicit grouping is performed by using a comma-delimited set of values.

To see how NFL teams have done after scoring fewer than 3, 7, 10, and 14 points use the SDQL:
Average(points) @ p:points < 3, 7, 10, 14
Groupings on both sides produce all occurring combinations.
A(points-o:points) as ‘Avg Margin’ @ 0, 10, 14 <= p:points < 10, 14, 21

The implicit and explicit grouping methods can be combined.

To see the average number of three pointers made for each team along with the league average use the SDQL:
Average(three pointers made) @ team,1 and season=2015
Or, since a Python string is as True as 1.
Average(three pointers made) @ team,League and season=2015

in summative

The third SDQL grouping is by the number of games over which to take a summative.

To see how many points NFL teams have given up, along with the number of qualifying games, after they had allowed an average of more than 40 points their last 1, 3 and 5 games, use the SDQL:
Average(o:points), Sum(1) @ Average(o:points@team and season,N=1,3,5) > 40