Using Max and Min Aggregate Functions in a Query

The following example demonstrates how to use the Max() aggregate function in a Where clause to identify the latest related part using the generation property. The Max() aggregate function returns the maximum value of a specified property. Similarly, the Min() aggregate function returns the minimum value of a specified property. You can use a statement like this in the conditional logic applied to either a Join or Where clause when defining a Query Definition.

  1. Go to Contents --> Administration --> Configuration --> Query Definitions. The menu shown in Figure 45 appears.

    Figure 45.

  2. Click Create New Query Definition. A blank Query Definition dialog appears.

    Figure 46.

  3. Enter the Query title in the Name field.
  4. Click the ellipses in the Context Item Type field and select Part.
  5. Click . The Show Editor button appears in the ribbon.

    Figure 47.

  6. Click the Show Editor button. The dialog appears displaying the context item.

    Figure 48.

  7. Right-click on the context item and select Add Related Item --> Using Item Property.

    Figure 49.

    The dialog box shown in figure 50 appears.

    Figure 50.

  8. Select config_id and click Add.

    Figure 51.

  9. Right-click the Where condition button and click Change Alias in the context menu:

    Figure 52.

    The Change Alias dialog appears.

    Figure 53.

  10. Change the alias to Part_LatestReleased_Filter and click .
  11. Click the Where condition button and create a join condition for the child Part as shown in Figure 54.

    Figure 54.

  12. Click the Where condition icon to create the where condition for the query as shown in Figure 55.

    Figure 55.

  13. Click Save.
  14. Select the parent Part and click the Where condition button to create the expression as shown in Figure 56.

Figure 56.

  1. Click Save. The Show Editor dialog displays the parent and child parts.

Figure 57.

The query returns the most recent version of released Parts associated with a particular config_id.