Understanding complex SQL queries
Build a complex SQL query.
Tutorial resources
These downloadable resources will be used to complete this tutorial:
Step-by-step guide
In its simplest form, SQL can be used to select objects for which an expression is true. In this exercise, you write a more complex SQL query to determine the count of the total number of minutes that the customer points experience pressure below 5 meters.
- From the Model Group, double click SQL Control to open the Baseline simulation results.
Note: If the run icon on the left of the simulation is greyed out, right-click the run and select Re-run.
- Right-click the Stored Query Group and select New > Stored Query.
In the popup, name the stored query “Customer Minutes Lost”.
- Click OK.
- From the Model Group, double-click Customer Minutes Lost to open the SQL dialog box.
- Expand the Object Type drop-down and select Customer Point.
- In the text box, copy and paste the query provided in the Customer minutes.txt file for this tutorial.
- Click Test.
A notification appears, stating that the syntax is valid.
- Click OK.
- Click Save.
- Click Run.
The SQL window closes, and an SQL results grid appears. In this case, there are zero minutes when customers experience less than 5 meters of pressure.
- Close the Baseline simulation.
Now, you can repeat this query with the Pipe Break scenario. Pipe 103874 has been set to rupture during the simulation.
- In the Model Group, double-click [Pipe Break] SQL Control to open it.
To rerun the query:
- Double-click the Customer Minutes Lost stored query.
- In the SQL dialog box, click Run.
Again, an SQL results grid appears.
Notice the difference in the result between the Baseline run and the Pipe Break run. Once the pipe has ruptured, there is significantly more time that customers experience less than 5 meters of pressure.
Be aware that you can find additional SQL syntax explanations and complex statements, as well as a list of SQL functions, in the WS Pro help pages on the Autodesk website.