Using Max and Min Aggregate Functions in a Query
Copy
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.
- Go to Contents --> Administration --> Configuration --> Query Definitions. The menu shown in Figure 45 appears.
- Click Create New Query Definition. A blank Query Definition dialog appears.
- Enter the Query title in the Name field.
- Click the ellipses in the Context Item Type field and select Part.
- Click the Show Editor button. The dialog appears displaying the context item.
- Right-click on the context item and select Add Related Item --> Using Item Property.
- Select config_id and click Add.
- Right-click the Where condition button and click Change Alias in the context menu:
- Click the Where condition button and create a join condition for the child Part as shown in Figure 54.
- Click the Where condition icon to create the where condition for the query as shown in Figure 55.
- Click Save.
- Select the parent Part and click the Where condition button to create the expression as shown in Figure 56.
- Click Save. The Show Editor dialog displays the parent and child parts.
Click
. The Show Editor button appears in the ribbon.
The dialog box shown in figure 50 appears.
The Change Alias dialog appears.
Change the alias to Part_LatestReleased_Filter and click
.
The query returns the most recent version of released Parts associated with a particular config_id.